CGAL:无法正确选择迭代器
CGAL: can't chose iterator correctly
我在 CGAL 库中从流 .txt 文件中的点构建了一个凸包 3d,并希望通过复制将它们插入到输出 .txt 文件中。
问题是要为 std::copy 选择迭代器,它可以对容器 Polyhedron_3 poly 中的顶点进行排序。这是我的代码:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/algorithm.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/convex_hull_3.h>
#include <vector>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K> Polyhedron_3;
typedef K::Segment_3 Segment_3;
// define point creator
typedef K::Point_3 Point_3;
typedef CGAL::Creator_uniform_3<double, Point_3> PointCreator;
//a functor computing the plane containing a triangular facet
struct Plane_from_facet {
Polyhedron_3::Plane_3 operator()(Polyhedron_3::Facet& f) {
Polyhedron_3::Halfedge_handle h = f.halfedge();
return Polyhedron_3::Plane_3( h->vertex()->point(),
h->next()->vertex()->point(),
h->opposite()->vertex()->point());
}
};
using namespace std;
int main()
{
std::ifstream fin("/Users/Arseniy/Documents/Course Work/Test Input.txt");
std::ofstream fout("/Users/Arseniy/Documents/Course Work/Test Output.txt");
CGAL::set_ascii_mode(fin);
CGAL::set_ascii_mode(fout);
std::istream_iterator< Point_3 > in_start(fin );
std::istream_iterator< Point_3 > in_end;
std::ostream_iterator< Point_3 > out( fout, "\n" );
std::vector<Point_3> points;
std::copy(in_start, in_end, std::back_inserter(points));
Polyhedron_3 poly;
// compute convex hull of non-collinear points
CGAL::convex_hull_3(points.begin(), points.end(), poly);
cout << "The convex hull contains " << poly.size_of_vertices() << " vertices" << std::endl;
cout << "The convex hull contains " << poly.size_of_facets() << " facets" << std::endl;
// assign a plane equation to each polyhedron facet using functor Plane_from_facet
std::transform(poly.facets_begin(), poly.facets_end(), poly.planes_begin(),Plane_from_facet());
std::copy(poly.vertices_begin(), poly.vertices_end(), ostream_iterator<int>(fout, ", "));
return 0;
}
我无法确定 ostream_iterator<> 的类型,它应该是 vertex_iterator,但不是。
我也试图描述
typedef Polyhedron::Vertex_iterator
但这也是一个错误的决定。
可以使用OFF 文件格式将多面体写入文件。
你可以简单地写:
std::ofstream fout("output.off");
fout << poly;
根据您的 CGAL 版本,您可能需要包含 CGAL/IO/Polyhedron_iostream.h
应该这样做:
std::copy(poly.points_begin(), poly.points_end(), ostream_iterator<Point_3>(fout, ", "));
我在 CGAL 库中从流 .txt 文件中的点构建了一个凸包 3d,并希望通过复制将它们插入到输出 .txt 文件中。 问题是要为 std::copy 选择迭代器,它可以对容器 Polyhedron_3 poly 中的顶点进行排序。这是我的代码:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/algorithm.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/convex_hull_3.h>
#include <vector>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedron_3<K> Polyhedron_3;
typedef K::Segment_3 Segment_3;
// define point creator
typedef K::Point_3 Point_3;
typedef CGAL::Creator_uniform_3<double, Point_3> PointCreator;
//a functor computing the plane containing a triangular facet
struct Plane_from_facet {
Polyhedron_3::Plane_3 operator()(Polyhedron_3::Facet& f) {
Polyhedron_3::Halfedge_handle h = f.halfedge();
return Polyhedron_3::Plane_3( h->vertex()->point(),
h->next()->vertex()->point(),
h->opposite()->vertex()->point());
}
};
using namespace std;
int main()
{
std::ifstream fin("/Users/Arseniy/Documents/Course Work/Test Input.txt");
std::ofstream fout("/Users/Arseniy/Documents/Course Work/Test Output.txt");
CGAL::set_ascii_mode(fin);
CGAL::set_ascii_mode(fout);
std::istream_iterator< Point_3 > in_start(fin );
std::istream_iterator< Point_3 > in_end;
std::ostream_iterator< Point_3 > out( fout, "\n" );
std::vector<Point_3> points;
std::copy(in_start, in_end, std::back_inserter(points));
Polyhedron_3 poly;
// compute convex hull of non-collinear points
CGAL::convex_hull_3(points.begin(), points.end(), poly);
cout << "The convex hull contains " << poly.size_of_vertices() << " vertices" << std::endl;
cout << "The convex hull contains " << poly.size_of_facets() << " facets" << std::endl;
// assign a plane equation to each polyhedron facet using functor Plane_from_facet
std::transform(poly.facets_begin(), poly.facets_end(), poly.planes_begin(),Plane_from_facet());
std::copy(poly.vertices_begin(), poly.vertices_end(), ostream_iterator<int>(fout, ", "));
return 0;
}
我无法确定 ostream_iterator<> 的类型,它应该是 vertex_iterator,但不是。
我也试图描述
typedef Polyhedron::Vertex_iterator
但这也是一个错误的决定。
可以使用OFF 文件格式将多面体写入文件。 你可以简单地写:
std::ofstream fout("output.off");
fout << poly;
根据您的 CGAL 版本,您可能需要包含 CGAL/IO/Polyhedron_iostream.h
应该这样做:
std::copy(poly.points_begin(), poly.points_end(), ostream_iterator<Point_3>(fout, ", "));