mirror of https://github.com/CGAL/cgal
Test triangulate_polygons()
This commit is contained in:
parent
7b375129fb
commit
6a0a0267bf
|
|
@ -1,13 +1,14 @@
|
||||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||||
|
|
||||||
#include <CGAL/Surface_mesh.h>
|
#include <CGAL/Surface_mesh.h>
|
||||||
|
|
||||||
|
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||||
|
|
||||||
#include <CGAL/boost/graph/copy_face_graph.h>
|
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||||
#include <CGAL/boost/graph/Dual.h>
|
#include <CGAL/boost/graph/Dual.h>
|
||||||
#include <CGAL/boost/graph/named_params_helper.h>
|
#include <CGAL/boost/graph/named_params_helper.h>
|
||||||
#include <CGAL/centroid.h>
|
#include <CGAL/centroid.h>
|
||||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
#include <CGAL/Polygon_mesh_processing/polygon_mesh_to_polygon_soup.h>
|
||||||
|
|
||||||
#include <boost/graph/filtered_graph.hpp>
|
#include <boost/graph/filtered_graph.hpp>
|
||||||
|
|
||||||
|
|
@ -117,21 +118,17 @@ test_triangulate_face()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int nb = 0;
|
|
||||||
for(typename boost::graph_traits<Surface_mesh>::face_descriptor fit : faces(mesh))
|
for(typename boost::graph_traits<Surface_mesh>::face_descriptor fit : faces(mesh))
|
||||||
{
|
{
|
||||||
if (nb > 4)
|
if (next(next(halfedge(fit, mesh), mesh), mesh) != prev(halfedge(fit, mesh), mesh))
|
||||||
break;
|
|
||||||
else if (next(next(halfedge(fit, mesh), mesh), mesh)
|
|
||||||
!= prev(halfedge(fit, mesh), mesh))
|
|
||||||
{
|
{
|
||||||
if(CGAL::Polygon_mesh_processing::triangulate_face(fit, mesh))
|
if(!CGAL::Polygon_mesh_processing::triangulate_face(fit, mesh))
|
||||||
++nb;
|
|
||||||
else
|
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(CGAL::is_triangle_mesh(mesh));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,6 +153,9 @@ test_triangulate_triangle_face()
|
||||||
if(!CGAL::Polygon_mesh_processing::triangulate_face(fit, mesh, CGAL::parameters::geom_traits(K())))
|
if(!CGAL::Polygon_mesh_processing::triangulate_face(fit, mesh, CGAL::parameters::geom_traits(K())))
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(CGAL::is_triangle_mesh(mesh));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,9 +238,54 @@ test_dual_with_various_faces()
|
||||||
if(!CGAL::Polygon_mesh_processing::triangulate_face(fit, sm_dual))
|
if(!CGAL::Polygon_mesh_processing::triangulate_face(fit, sm_dual))
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(CGAL::is_triangle_mesh(sm_dual));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename K>
|
||||||
|
bool
|
||||||
|
test_triangulate_soup()
|
||||||
|
{
|
||||||
|
typedef typename K::Point_3 Point;
|
||||||
|
typedef CGAL::Surface_mesh<Point> Surface_mesh;
|
||||||
|
|
||||||
|
Surface_mesh mesh;
|
||||||
|
std::ifstream input(CGAL::data_file_path("meshes/elephant.off"));
|
||||||
|
|
||||||
|
if (!input || !(input >> mesh) || mesh.is_empty())
|
||||||
|
{
|
||||||
|
std::cerr << "Not a valid off file." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef typename boost::property_map<Surface_mesh, boost::vertex_point_t>::type Pmap;
|
||||||
|
Pmap vpmap = get_property_map(boost::vertex_point, mesh);
|
||||||
|
|
||||||
|
CGAL::Dual<Surface_mesh> dual(mesh);
|
||||||
|
// copy dual to a sm
|
||||||
|
Surface_mesh sm_dual;
|
||||||
|
CGAL::copy_face_graph(dual, sm_dual,
|
||||||
|
CGAL::parameters::vertex_point_map(
|
||||||
|
Dual_vpm<Surface_mesh, Point, Pmap>(mesh, vpmap)));
|
||||||
|
|
||||||
|
std::vector<Point> points;
|
||||||
|
std::vector<std::vector<std::size_t> > polygons;
|
||||||
|
CGAL::Polygon_mesh_processing::polygon_mesh_to_polygon_soup(sm_dual, points, polygons);
|
||||||
|
|
||||||
|
bool success = CGAL::Polygon_mesh_processing::triangulate_polygons(points, polygons);
|
||||||
|
for(std::size_t i = 0; i < polygons.size(); ++i)
|
||||||
|
{
|
||||||
|
assert(polygons[i].size() == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For compilation
|
||||||
|
success = CGAL::Polygon_mesh_processing::triangulate_polygons(points, polygons, CGAL::parameters::geom_traits(K()));
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
assert(test_triangulate_faces<Epic>());
|
assert(test_triangulate_faces<Epic>());
|
||||||
|
|
@ -249,6 +294,7 @@ int main()
|
||||||
assert(test_triangulate_face<Epic>());
|
assert(test_triangulate_face<Epic>());
|
||||||
assert(test_triangulate_triangle_face<Epic>());
|
assert(test_triangulate_triangle_face<Epic>());
|
||||||
assert(test_dual_with_various_faces<Epic>());
|
assert(test_dual_with_various_faces<Epic>());
|
||||||
|
assert(test_triangulate_soup<Epic>());
|
||||||
|
|
||||||
assert(test_triangulate_faces<Epec>());
|
assert(test_triangulate_faces<Epec>());
|
||||||
assert(test_triangulate_faces_with_named_parameters<Epec>());
|
assert(test_triangulate_faces_with_named_parameters<Epec>());
|
||||||
|
|
@ -256,6 +302,8 @@ int main()
|
||||||
assert(test_triangulate_face<Epec>());
|
assert(test_triangulate_face<Epec>());
|
||||||
assert(test_triangulate_triangle_face<Epec>());
|
assert(test_triangulate_triangle_face<Epec>());
|
||||||
assert(test_dual_with_various_faces<Epec>());
|
assert(test_dual_with_various_faces<Epec>());
|
||||||
|
assert(test_triangulate_soup<Epec>());
|
||||||
|
|
||||||
|
std::cout << "Done" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue