【发布时间】:2014-03-13 16:56:36
【问题描述】:
例如,当我尝试为映射分配值时,我正在尝试创建 map<int,CGAL::AABB_tree<Traits>> 类型的 STL 映射(AABB tree's 的映射)(此代码仅用于演示目的):
//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's 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);
我收到以下错误:
错误 C2248: 'CGAL::AABB_tree::operator =' : 不能 访问在类 'CGAL::AABB_tree
中声明的私有成员'
我尝试查看 CGAL 的源代码,在 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);
这意味着复制和赋值构造函数是私有的,因此无法创建 树类型的 stl 容器。
我尝试使用指针而不是我将地图更改为map<int,CGAL::AABB_tree < Traits > * >
并尝试过:
BuildMesh<HalfedgeDS> mesh(V, F);
polyhedron.delegate( mesh);
myMap[someInt] = new Tree(polyhedron.facets_begin(),polyhedron.facets_end(),polyhedron);
但是它使我的代码崩溃了。
有什么办法可以创建这种类型的 STL 容器吗?
2014 年 14 月 3 日更新
我尝试按照建议使用 Drop 的解决方案,但出现以下错误:
错误 C2248:“CGAL::AABB_tree::AABB_tree”:无法访问 在类 'CGAL::AABB_tree' 中声明的私有成员
2014 年 3 月 17 日更新
这是一个无法编译的示例代码:
#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;
}
有什么想法吗?
【问题讨论】:
-
究竟是什么“崩溃”了?您使用调试器,不是吗? (智能)指针的替代方法可以是添加一个间接级别:将您的数据放入包装类并为其定义复制语义,然后制作一个包装容器。
-
我正在编写一个 mex 文件,所以调试很困难。我确实将数据放在了一个包装类中,但是不可能编写复制语义,因为 AABB 树没有复制语义,所以我无法复制它......
标签: c++ containers computational-geometry cgal