CGAL 中的表面网格生成代码,未编译
Surface Mesh Generation Code in CGAL, not compiling
我试图利用 CGAL 的表面重建功能(完全取自 here,但我一直收到错误消息:
In file included from /usr/include/CGAL/IO/output_surface_facets_to_polyhedron.h:25:0,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:14,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/value_type_traits.h: In instantiation of ‘struct CGAL::value_type_traits<CGAL::Point_with_normal_3<CGAL::Epick> >’:
/usr/include/CGAL/Point_with_normal_3.h:165:1: required by substitution of ‘template<class Iter> CGAL::Normal_of_point_with_normal_pmap<typename CGAL::Kernel_traits<typename CGAL::value_type_traits<T>::type>::Kernel> CGAL::make_normal_of_point_with_normal_pmap(Iter) [with Iter = CGAL::Point_with_normal_3<CGAL::Epick>]’
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:21:113: required from here
/usr/include/CGAL/value_type_traits.h:40:56: error: no type named ‘value_type’ in ‘struct std::iterator_traits<CGAL::Point_with_normal_3<CGAL::Epick> >’
typedef typename std::iterator_traits<T>::value_type type;
^
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp: In static member function ‘static void CGALDelaunay::TriangulateUsingCGAL()’:
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:21:113: error: no matching function for call to ‘make_normal_of_point_with_normal_pmap(std::vector<CGAL::Point_with_normal_3<CGAL::Epick> >::value_type)’
CGAL::make_normal_of_point_with_normal_pmap(PointList::value_type()) );
^
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:21:113: note: candidate is:
In file included from /usr/include/CGAL/Reconstruction_triangulation_3.h:25:0,
from /usr/include/CGAL/Poisson_reconstruction_function.h:35,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:15,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/Point_with_normal_3.h:165:1: note: template<class Iter> CGAL::Normal_of_point_with_normal_pmap<typename CGAL::Kernel_traits<typename CGAL::value_type_traits<T>::type>::Kernel> CGAL::make_normal_of_point_with_normal_pmap(Iter)
make_normal_of_point_with_normal_pmap(Iter)
^
/usr/include/CGAL/Point_with_normal_3.h:165:1: note: substitution of deduced template arguments resulted in errors seen above
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: error: no matching function for call to ‘CGAL::Poisson_reconstruction_function<CGAL::Epick>::compute_implicit_function()’
if ( ! function.compute_implicit_function() )
^
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: note: candidates are:
In file included from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:15:0,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/Poisson_reconstruction_function.h:366:8: note: template<class SparseLinearAlgebraTraits_d, class Visitor> bool CGAL::Poisson_reconstruction_function<Gt>::compute_implicit_function(SparseLinearAlgebraTraits_d, Visitor, double, double) [with SparseLinearAlgebraTraits_d = SparseLinearAlgebraTraits_d; Visitor = Visitor; Gt = CGAL::Epick]
bool compute_implicit_function(
^
/usr/include/CGAL/Poisson_reconstruction_function.h:366:8: note: template argument deduction/substitution failed:
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: note: candidate expects 4 arguments, 0 provided
if ( ! function.compute_implicit_function() )
^
In file included from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:15:0,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/Poisson_reconstruction_function.h:519:8: note: template<class SparseLinearAlgebraTraits_d> bool CGAL::Poisson_reconstruction_function<Gt>::compute_implicit_function(SparseLinearAlgebraTraits_d, bool) [with SparseLinearAlgebraTraits_d = SparseLinearAlgebraTraits_d; Gt = CGAL::Epick]
bool compute_implicit_function(SparseLinearAlgebraTraits_d solver, bool smoother_hole_filling = false)
^
/usr/include/CGAL/Poisson_reconstruction_function.h:519:8: note: template argument deduction/substitution failed:
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: note: candidate expects 2 arguments, 0 provided
if ( ! function.compute_implicit_function() )
我完全不知道为什么这不起作用,任何建议将不胜感激。
代码如下:
(Header file)
#include <CGAL/trace.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Surface_mesh_default_triangulation_3.h>
#include <CGAL/make_surface_mesh.h>
#include <CGAL/Implicit_surface_3.h>
#include <CGAL/IO/output_surface_facets_to_polyhedron.h>
#include <CGAL/Poisson_reconstruction_function.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/compute_average_spacing.h>
#include <vector>
#include <fstream>
using namespace std;
// Type
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal;
typedef Kernel::Sphere_3 Sphere;
typedef std::vector<Point_with_normal> PointList;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Poisson_reconstruction_function<Kernel> Poisson_reconstruction_function;
typedef CGAL::Surface_mesh_default_triangulation_3 STr;
typedef CGAL::Surface_mesh_complex_2_in_triangulation_3<STr> C2t3;
typedef CGAL::Implicit_surface_3<Kernel, Poisson_reconstruction_function> Surface_3;
class CGALDelaunay
{
public:
static void TriangulateUsingCGAL();
};
CPP 文件:
#include "mesh_map/CGALDelaunayTriangulation.h"
void CGALDelaunay::TriangulateUsingCGAL()
{
// Poisson options
FT sm_angle = 20.0; // Min triangle angle in degrees.
FT sm_radius = 30; // Max triangle size w.r.t. point set average spacing.
FT sm_distance = 0.375; // Surface Approximation error w.r.t. point set average spacing.
// Reads the point set file in points[].
// Note: read_xyz_points_and_normals() requires an iterator over points
// + property maps to access each point's position and normal.
// The position property map can be omitted here as we use iterators over Point_3 elements.
PointList points;
// Creates implicit function from the read points using the default solver.
// Note: this method requires an iterator over points
// + property maps to access each point's position and normal.
// The position property map can be omitted here as we use iterators over Point_3 elements.
Poisson_reconstruction_function function(points.begin(), points.end(),
CGAL::make_normal_of_point_with_normal_pmap(PointList::value_type()) );
// Computes the Poisson indicator function f()
// at each vertex of the triangulation.
if ( ! function.compute_implicit_function() )
return EXIT_FAILURE;
// Computes average spacing
FT average_spacing = CGAL::compute_average_spacing(points.begin(), points.end(),
6 /* knn = 1 ring */);
// Gets one point inside the implicit surface
// and computes implicit function bounding sphere radius.
Point inner_point = function.get_inner_point();
Sphere bsphere = function.bounding_sphere();
FT radius = std::sqrt(bsphere.squared_radius());
// Defines the implicit surface: requires defining a
// conservative bounding sphere centered at inner point.
FT sm_sphere_radius = 5.0 * radius;
FT sm_dichotomy_error = sm_distance*average_spacing/1000.0; // Dichotomy error must be << sm_distance
Surface_3 surface(function,
Sphere(inner_point,sm_sphere_radius*sm_sphere_radius),
sm_dichotomy_error/sm_sphere_radius);
// Defines surface mesh generation criteria
CGAL::Surface_mesh_default_criteria_3<STr> criteria(sm_angle, // Min triangle angle (degrees)
sm_radius*average_spacing, // Max triangle size
sm_distance*average_spacing); // Approximation error
// Generates surface mesh with manifold option
STr tr; // 3D Delaunay triangulation for surface mesh generation
C2t3 c2t3(tr); // 2D complex in 3D Delaunay triangulation
CGAL::make_surface_mesh(c2t3, // reconstructed mesh
surface, // implicit surface
criteria, // meshing criteria
CGAL::Manifold_with_boundary_tag()); // require manifold mesh
}
如 here 所述,如果定义了 CGAL_EIGEN3_ENABLED,则不需要求解器参数的 compute_implicit_function()
重载可用。您还需要安装 Eigen 并可供您的编译器使用。
在 cmake 级别,这是通过这些命令完成的
find_package(Eigen3 3.1.0)
if (EIGEN3_FOUND)
include( ${EIGEN3_USE_FILE} )
endif()
此外,您 return 函数中的值期望 void 作为 return 类型。
我试图利用 CGAL 的表面重建功能(完全取自 here,但我一直收到错误消息:
In file included from /usr/include/CGAL/IO/output_surface_facets_to_polyhedron.h:25:0,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:14,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/value_type_traits.h: In instantiation of ‘struct CGAL::value_type_traits<CGAL::Point_with_normal_3<CGAL::Epick> >’:
/usr/include/CGAL/Point_with_normal_3.h:165:1: required by substitution of ‘template<class Iter> CGAL::Normal_of_point_with_normal_pmap<typename CGAL::Kernel_traits<typename CGAL::value_type_traits<T>::type>::Kernel> CGAL::make_normal_of_point_with_normal_pmap(Iter) [with Iter = CGAL::Point_with_normal_3<CGAL::Epick>]’
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:21:113: required from here
/usr/include/CGAL/value_type_traits.h:40:56: error: no type named ‘value_type’ in ‘struct std::iterator_traits<CGAL::Point_with_normal_3<CGAL::Epick> >’
typedef typename std::iterator_traits<T>::value_type type;
^
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp: In static member function ‘static void CGALDelaunay::TriangulateUsingCGAL()’:
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:21:113: error: no matching function for call to ‘make_normal_of_point_with_normal_pmap(std::vector<CGAL::Point_with_normal_3<CGAL::Epick> >::value_type)’
CGAL::make_normal_of_point_with_normal_pmap(PointList::value_type()) );
^
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:21:113: note: candidate is:
In file included from /usr/include/CGAL/Reconstruction_triangulation_3.h:25:0,
from /usr/include/CGAL/Poisson_reconstruction_function.h:35,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:15,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/Point_with_normal_3.h:165:1: note: template<class Iter> CGAL::Normal_of_point_with_normal_pmap<typename CGAL::Kernel_traits<typename CGAL::value_type_traits<T>::type>::Kernel> CGAL::make_normal_of_point_with_normal_pmap(Iter)
make_normal_of_point_with_normal_pmap(Iter)
^
/usr/include/CGAL/Point_with_normal_3.h:165:1: note: substitution of deduced template arguments resulted in errors seen above
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: error: no matching function for call to ‘CGAL::Poisson_reconstruction_function<CGAL::Epick>::compute_implicit_function()’
if ( ! function.compute_implicit_function() )
^
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: note: candidates are:
In file included from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:15:0,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/Poisson_reconstruction_function.h:366:8: note: template<class SparseLinearAlgebraTraits_d, class Visitor> bool CGAL::Poisson_reconstruction_function<Gt>::compute_implicit_function(SparseLinearAlgebraTraits_d, Visitor, double, double) [with SparseLinearAlgebraTraits_d = SparseLinearAlgebraTraits_d; Visitor = Visitor; Gt = CGAL::Epick]
bool compute_implicit_function(
^
/usr/include/CGAL/Poisson_reconstruction_function.h:366:8: note: template argument deduction/substitution failed:
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: note: candidate expects 4 arguments, 0 provided
if ( ! function.compute_implicit_function() )
^
In file included from /home/mrsl_student/git/catkin_ws/src/mesh_map/include/mesh_map/CGALDelaunayTriangulation.h:15:0,
from /home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:3:
/usr/include/CGAL/Poisson_reconstruction_function.h:519:8: note: template<class SparseLinearAlgebraTraits_d> bool CGAL::Poisson_reconstruction_function<Gt>::compute_implicit_function(SparseLinearAlgebraTraits_d, bool) [with SparseLinearAlgebraTraits_d = SparseLinearAlgebraTraits_d; Gt = CGAL::Epick]
bool compute_implicit_function(SparseLinearAlgebraTraits_d solver, bool smoother_hole_filling = false)
^
/usr/include/CGAL/Poisson_reconstruction_function.h:519:8: note: template argument deduction/substitution failed:
/home/mrsl_student/git/catkin_ws/src/mesh_map/src/CGALDelaunayTriangulation.cpp:24:47: note: candidate expects 2 arguments, 0 provided
if ( ! function.compute_implicit_function() )
我完全不知道为什么这不起作用,任何建议将不胜感激。
代码如下:
(Header file)
#include <CGAL/trace.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Surface_mesh_default_triangulation_3.h>
#include <CGAL/make_surface_mesh.h>
#include <CGAL/Implicit_surface_3.h>
#include <CGAL/IO/output_surface_facets_to_polyhedron.h>
#include <CGAL/Poisson_reconstruction_function.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/compute_average_spacing.h>
#include <vector>
#include <fstream>
using namespace std;
// Type
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal;
typedef Kernel::Sphere_3 Sphere;
typedef std::vector<Point_with_normal> PointList;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Poisson_reconstruction_function<Kernel> Poisson_reconstruction_function;
typedef CGAL::Surface_mesh_default_triangulation_3 STr;
typedef CGAL::Surface_mesh_complex_2_in_triangulation_3<STr> C2t3;
typedef CGAL::Implicit_surface_3<Kernel, Poisson_reconstruction_function> Surface_3;
class CGALDelaunay
{
public:
static void TriangulateUsingCGAL();
};
CPP 文件:
#include "mesh_map/CGALDelaunayTriangulation.h"
void CGALDelaunay::TriangulateUsingCGAL()
{
// Poisson options
FT sm_angle = 20.0; // Min triangle angle in degrees.
FT sm_radius = 30; // Max triangle size w.r.t. point set average spacing.
FT sm_distance = 0.375; // Surface Approximation error w.r.t. point set average spacing.
// Reads the point set file in points[].
// Note: read_xyz_points_and_normals() requires an iterator over points
// + property maps to access each point's position and normal.
// The position property map can be omitted here as we use iterators over Point_3 elements.
PointList points;
// Creates implicit function from the read points using the default solver.
// Note: this method requires an iterator over points
// + property maps to access each point's position and normal.
// The position property map can be omitted here as we use iterators over Point_3 elements.
Poisson_reconstruction_function function(points.begin(), points.end(),
CGAL::make_normal_of_point_with_normal_pmap(PointList::value_type()) );
// Computes the Poisson indicator function f()
// at each vertex of the triangulation.
if ( ! function.compute_implicit_function() )
return EXIT_FAILURE;
// Computes average spacing
FT average_spacing = CGAL::compute_average_spacing(points.begin(), points.end(),
6 /* knn = 1 ring */);
// Gets one point inside the implicit surface
// and computes implicit function bounding sphere radius.
Point inner_point = function.get_inner_point();
Sphere bsphere = function.bounding_sphere();
FT radius = std::sqrt(bsphere.squared_radius());
// Defines the implicit surface: requires defining a
// conservative bounding sphere centered at inner point.
FT sm_sphere_radius = 5.0 * radius;
FT sm_dichotomy_error = sm_distance*average_spacing/1000.0; // Dichotomy error must be << sm_distance
Surface_3 surface(function,
Sphere(inner_point,sm_sphere_radius*sm_sphere_radius),
sm_dichotomy_error/sm_sphere_radius);
// Defines surface mesh generation criteria
CGAL::Surface_mesh_default_criteria_3<STr> criteria(sm_angle, // Min triangle angle (degrees)
sm_radius*average_spacing, // Max triangle size
sm_distance*average_spacing); // Approximation error
// Generates surface mesh with manifold option
STr tr; // 3D Delaunay triangulation for surface mesh generation
C2t3 c2t3(tr); // 2D complex in 3D Delaunay triangulation
CGAL::make_surface_mesh(c2t3, // reconstructed mesh
surface, // implicit surface
criteria, // meshing criteria
CGAL::Manifold_with_boundary_tag()); // require manifold mesh
}
如 here 所述,如果定义了 CGAL_EIGEN3_ENABLED,则不需要求解器参数的 compute_implicit_function()
重载可用。您还需要安装 Eigen 并可供您的编译器使用。
在 cmake 级别,这是通过这些命令完成的
find_package(Eigen3 3.1.0)
if (EIGEN3_FOUND)
include( ${EIGEN3_USE_FILE} )
endif()
此外,您 return 函数中的值期望 void 作为 return 类型。