我正在尝试编写CGAL安排及其应用书中的一个例子:Efi Fogel,Dan Halperin,Ron Wein的循序渐进指南。可以在此链接中看到该示例:
出于某种原因,我得到了一个非常模糊的激烈编译错误。这是我到目前为止所写的内容:
这是实际投射阴影的主要功能。我已经注释了导致编译错误的行,并在下面发布了错误。
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <string>
#include <CGAL/Cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Direction_3.h>
#include <fstream>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Polyhedron_traits_with_normals_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Gps_iostream.h>
#include "Normal_equation.h"
#include "bops_set_linear.h"
typedef double Real;
//typedef CGAL::Cartesian<Real> Kernel0;
// Use a filtered kernel so that all predicates are exact.
//typedef CGAL::Filtered_kernel<Kernel0> Kernel;
typedef CGAL::Polyhedron_traits_with_normals_3<Kernel> Polyhedron_traits;
typedef CGAL:: Polyhedron_3<Polyhedron_traits> Polyhedron;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Plane_3 Plane_3;
typedef Kernel::Direction_3 Direction_3;
int main(int argc, char* argv[]){
CGAL_assertion(argc > 3);
Kernel::FT x = boost::lexical_cast<double>(argv[1]); //Take in x coordinate for shadow plane
Kernel::FT y = boost::lexical_cast<double>(argv[2]); //Take in y coordinate for shadow plane
Kernel::FT z = boost::lexical_cast<double>(argv[3]); //Take in z coordinate for shadow plane
Direction_3 direction(x, y, z);
const char* filename = (argc > 4) ? argv[4] : "hand.off";
std::ifstream inFile(filename);
if (!inFile.is_open()){
std::cerr << "Failed to open file " << filename << "\n";
exit(1);
}
Polyhedron polyhedron;
inFile >> polyhedron;
std::transform(polyhedron.facets_begin(), polyhedron.facets_end(), polyhedron.planes_begin(), Normal_equation());
std::list<Polygon> polygons;
Kernel kernel;
Kernel::Compare_z_3 cmp_z = kernel.compare_z_3_object();
Kernel::Construct_projected_xy_point_2 proj = kernel.construct_projected_xy_point_2_object();
Kernel::Construct_translated_point_3 translate = kernel.construct_translated_point_3_object();
Point_3 origin = kernel.construct_point_3_object()(CGAL::ORIGIN);
Plane_3 plane = kernel.construct_plane_3_object()(origin, direction);
Point_3 r = translate(origin, direction.vector());
for (Polyhedron::Facet_const_iterator fit = polyhedron.facets_begin(); fit != polyhedron.facets_end(); ++fit){
if (CGAL::angle(translate(origin, fit->plane()), origin, r) == CGAL::OBTUSE) continue;
//Go over the facet vertices and project them
Polygon polygon;
Polyhedron::Halfedge_around_facet_const_circulator hit = fit->facet_begin();
do{
const Point_3& point = hit->vertex()->point();
polygon.push_back(proj(plane, point));
} while (++hit != fit->facet_begin());
polygons.push_back(polygon);
}
polyhedron.clear();
Polygon_set S;
S.join(polygons.begin(), polygons.end()); //THIS IS THE LINE CAUSING THE COMPILE ERROR
std::cout << S;
return 0;
}
这是Normal_equation.h中的Normal_Equation结构
struct Normal_equation{
template <typename Facet> typename Facet::Plane_3 operator()(Facet & f){
typename Facet::Halfedge_handle h = f.halfedge();
return CGAL::cross_product(h->next()->vertex()->point() - h->vertex()->point(), h->next()->next()->vertex()->point() - h->next()->vertex()->point());
}
};
以下两个文件用作类型设置器: bops_linear.h
#ifndef BOPS_LINEAR_H
#define BOPS_LINEAR_H
#include <list>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef std::list<Polygon_with_holes> Pgn_with_holes_container;
#endif
bops_set_linear.h
#ifndef BOPS_SET_LINEAR_H
#define BOPS_SET_LINEAR_H
#include "bops_linear.h"
#include <CGAL/Polygon_set_2.h>
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
#endif
我不是这个东西的专家所以我包含了我的Makefile,所以你可以看到我已经链接的
CXX = g++
CXXFLAGS = -g -O -frounding-math
Link = -lCGAL -lmpfr -lgmp -DBOOST_LOG_DYN_LINK -lboost_thread
all: main
main: main.cpp Normal_equation.h
$(CXX) $(CXXFLAGS) -o $@ main.cpp $(Link)
clean:
rm -f main.o main
这里真的很讨厌。编译错误长达一英里,而且非常模糊。这有点超出我的意义。我为这篇文章填写了字符数,所以我把它发布在我的Onedrive中,你可以在这里看到它:http://1drv.ms/1eHZkuq
答案 0 :(得分:0)
我不知道为什么,但我设法通过更改内核来编译它。我将文件bops_liner.h更改为
#ifndef BOPS_LINEAR_H
#define BOPS_LINEAR_H
#include <list>
#include <CGAL/Simple_cartesian.h>
//#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
typedef double Real;
typedef CGAL::Simple_cartesian<Real> Kernel;
//typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef std::list<Polygon_with_holes> Pgn_with_holes_container;
#endif