mirror of https://github.com/CGAL/cgal
using the new Shape_detection implementation (instead of the deprecated Shape_detection_3)
This commit is contained in:
parent
fadaee63a8
commit
3b9c73c917
|
|
@ -1206,3 +1206,5 @@ gmon.*
|
|||
/Stream_support/test/Stream_support/cgal_test_with_cmake
|
||||
/*.html
|
||||
/Snap_rounding_2/test/Snap_rounding_2/data/out
|
||||
Polygonal_surface_reconstruction/examples/build*
|
||||
Polygonal_surface_reconstruction/test/build*
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#include <CGAL/IO/read_xyz_points.h>
|
||||
#include <CGAL/IO/Writer_OFF.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/Shape_detection_3.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/Shape_detection/Efficient_RANSAC.h>
|
||||
#include <CGAL/Polygonal_surface_reconstruction.h>
|
||||
#include <CGAL/SCIP_mixed_integer_program_traits.h>
|
||||
#include <CGAL/Timer.h>
|
||||
|
|
@ -23,10 +23,11 @@ typedef CGAL::Nth_of_tuple_property_map<0, PNI> Point_map;
|
|||
typedef CGAL::Nth_of_tuple_property_map<1, PNI> Normal_map;
|
||||
typedef CGAL::Nth_of_tuple_property_map<2, PNI> Plane_index_map;
|
||||
|
||||
typedef CGAL::Shape_detection_3::Shape_detection_traits<Kernel, Point_vector, Point_map, Normal_map> Traits;
|
||||
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
|
||||
typedef CGAL::Shape_detection_3::Plane<Traits> Plane;
|
||||
typedef CGAL::Shape_detection_3::Point_to_shape_index_map<Traits> Point_to_shape_index_map;
|
||||
typedef CGAL::Shape_detection::Efficient_RANSAC_traits<Kernel, Point_vector, Point_map, Normal_map> Traits;
|
||||
|
||||
typedef CGAL::Shape_detection::Efficient_RANSAC<Traits> Efficient_ransac;
|
||||
typedef CGAL::Shape_detection::Plane<Traits> Plane;
|
||||
typedef CGAL::Shape_detection::Point_to_shape_index_map<Traits> Point_to_shape_index_map;
|
||||
|
||||
typedef CGAL::Polygonal_surface_reconstruction<Kernel> Polygonal_surface_reconstruction;
|
||||
typedef CGAL::Surface_mesh<Point> Surface_mesh;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
|
||||
#ifndef SKIP_TEST_USING_GLPK
|
||||
#include <CGAL/GLPK_mixed_integer_program_traits.h>
|
||||
|
|
@ -32,16 +31,16 @@ typedef CGAL::GLPK_mixed_integer_program_traits<double> GLPK_Solver;
|
|||
typedef CGAL::SCIP_mixed_integer_program_traits<double> SCIP_Solver;
|
||||
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
std::cerr << "Testing the Polygonal Surface Reconstruction method...\n\n";
|
||||
std::cerr << "Testing the Polygonal Surface Reconstruction method...\n";
|
||||
|
||||
#if 0
|
||||
argc = 2;
|
||||
argv[1] = "data/icosahedron.pwn";
|
||||
//argv[1] = "data/house.ply";
|
||||
//argv[1] = "data/chair.ply";
|
||||
//argv[1] = "data/square.ply";
|
||||
argv[1] = "data/icosahedron.pwn";
|
||||
//argv[1] = "data/house.ply";
|
||||
//argv[1] = "data/chair.ply";
|
||||
//argv[1] = "data/square.ply";
|
||||
#endif
|
||||
|
||||
// usage
|
||||
|
|
@ -49,7 +48,7 @@ int main(int argc, char * argv[])
|
|||
std::cerr << "For the input point cloud, reconstruct a water-tight polygonal surface.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " point_cloud_file" << std::endl;
|
||||
std::cerr << "Input file formats are \'pwn\' and \'ply\'. No output.\n\n";
|
||||
std::cerr << "Input file formats are \'pwn\' and \'ply\'. No output.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
@ -57,50 +56,50 @@ int main(int argc, char * argv[])
|
|||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
std::cerr << "--- Using Simple cartesian kernel\n\n";
|
||||
std::cerr << "--- Using Simple cartesian kernel";
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#ifndef SKIP_TEST_USING_GLPK
|
||||
std::cerr << "\n\t---- Using GLPK solver\n\n";
|
||||
std::cerr << "\n\t---- Using GLPK solver\n";
|
||||
|
||||
std::cerr << "\t\t---- using provided planes\n";
|
||||
reconstruct<Cartesian, GLPK_Solver>(input_file, false);
|
||||
|
||||
std::cerr << "\n\t\t---- re-extract planes\n";
|
||||
std::cerr << "\t\t---- re-extract planes\n";
|
||||
reconstruct<Cartesian, GLPK_Solver>(input_file, true);
|
||||
#endif
|
||||
|
||||
std::cerr << "\n\t---- Using SCIP solver\n\n";
|
||||
std::cerr << "\n\t---- Using SCIP solver\n";
|
||||
|
||||
std::cerr << "\t\t---- using provided planes\n";
|
||||
reconstruct<Cartesian, SCIP_Solver>(input_file, false);
|
||||
|
||||
std::cerr << "\n\t\t---- re-extract planes\n\n";
|
||||
std::cerr << "\t\t---- re-extract planes\n";
|
||||
reconstruct<Cartesian, SCIP_Solver>(input_file, true);
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
std::cerr << "\n--- Using Epick kernel\n\n";
|
||||
std::cerr << "\n--- Using Epick kernel";
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
#ifndef SKIP_TEST_USING_GLPK
|
||||
std::cerr << "\t---- Using GLPK solver\n\n";
|
||||
std::cerr << "\n\t---- Using GLPK solver\n";
|
||||
|
||||
std::cerr << "\t\t---- using provided planes\n";
|
||||
reconstruct<Epick, GLPK_Solver>(input_file, false);
|
||||
|
||||
std::cerr << "\n\t\t---- re-extract planes\n";
|
||||
std::cerr << "\t\t---- re-extract planes\n";
|
||||
reconstruct<Epick, GLPK_Solver>(input_file, true);
|
||||
#endif
|
||||
|
||||
std::cerr << "\n\t---- Using SCIP solver\n\n";
|
||||
std::cerr << "\n\t---- Using SCIP solver\n";
|
||||
|
||||
std::cerr << "\t\t---- using provided planes\n";
|
||||
reconstruct<Epick, SCIP_Solver>(input_file, false);
|
||||
|
||||
std::cerr << "\n\t\t---- re-extract planes\n";
|
||||
std::cerr << "\t\t---- re-extract planes\n";
|
||||
reconstruct<Epick, SCIP_Solver>(input_file, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
#include <CGAL/IO/read_xyz_points.h>
|
||||
#include <CGAL/IO/read_ply_points.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/Shape_detection_3.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/Shape_detection/Efficient_RANSAC.h>
|
||||
#include <CGAL/Polygonal_surface_reconstruction.h>
|
||||
#include <CGAL/Timer.h>
|
||||
|
||||
|
|
@ -22,32 +22,32 @@
|
|||
template <typename Kernel, typename MIP_Solver>
|
||||
int reconstruct(const std::string& input_file, bool force_extract_planes)
|
||||
{
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
typedef CGAL::Polygonal_surface_reconstruction<Kernel> Polygonal_surface_reconstruction;
|
||||
typedef CGAL::Surface_mesh<Point> Surface_mesh;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
typedef CGAL::Polygonal_surface_reconstruction<Kernel> Polygonal_surface_reconstruction;
|
||||
typedef CGAL::Surface_mesh<Point> Surface_mesh;
|
||||
|
||||
// Point with normal, and plane index
|
||||
typedef boost::tuple<Point, Vector, int> PNI;
|
||||
typedef std::vector<PNI> Point_vector;
|
||||
typedef CGAL::Nth_of_tuple_property_map<0, PNI> Point_map;
|
||||
typedef CGAL::Nth_of_tuple_property_map<1, PNI> Normal_map;
|
||||
typedef CGAL::Nth_of_tuple_property_map<2, PNI> Plane_index_map;
|
||||
// Point with normal, and plane index
|
||||
typedef boost::tuple<Point, Vector, int> PNI;
|
||||
typedef std::vector<PNI> Point_vector;
|
||||
typedef CGAL::Nth_of_tuple_property_map<0, PNI> Point_map;
|
||||
typedef CGAL::Nth_of_tuple_property_map<1, PNI> Normal_map;
|
||||
typedef CGAL::Nth_of_tuple_property_map<2, PNI> Plane_index_map;
|
||||
|
||||
typedef CGAL::Shape_detection_3::Shape_detection_traits<Kernel, Point_vector, Point_map, Normal_map> Traits;
|
||||
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
|
||||
typedef CGAL::Shape_detection_3::Plane<Traits> Plane;
|
||||
typedef CGAL::Shape_detection_3::Point_to_shape_index_map<Traits> Point_to_shape_index_map;
|
||||
typedef CGAL::Shape_detection::Efficient_RANSAC_traits<Kernel, Point_vector, Point_map, Normal_map> Traits;
|
||||
|
||||
typedef CGAL::Shape_detection::Efficient_RANSAC<Traits> Efficient_ransac;
|
||||
typedef CGAL::Shape_detection::Plane<Traits> Plane;
|
||||
typedef CGAL::Shape_detection::Point_to_shape_index_map<Traits> Point_to_shape_index_map;
|
||||
|
||||
Point_vector points;
|
||||
|
||||
// Loads point set from a file.
|
||||
std::ifstream input_stream(input_file.c_str());
|
||||
if (!input_stream) {
|
||||
std::cerr << " Error: cannot read file " << input_file << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!input_stream) {
|
||||
std::cerr << " Error: cannot read file " << input_file << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cout << "\t\t\tLoading point cloud: " << input_file << "...";
|
||||
|
||||
std::string extension = input_file.substr(input_file.find_last_of('.'));
|
||||
|
|
@ -57,34 +57,34 @@ int reconstruct(const std::string& input_file, bool force_extract_planes)
|
|||
CGAL::Timer t;
|
||||
t.start();
|
||||
if (extension == ".pwn") {
|
||||
if (!CGAL::read_xyz_points(
|
||||
input_stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::parameters::point_map(Point_map()).normal_map(Normal_map())))
|
||||
if (!CGAL::read_xyz_points(
|
||||
input_stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::parameters::point_map(Point_map()).normal_map(Normal_map())))
|
||||
{
|
||||
std::cerr << " Error: cannot read file " << input_file << std::endl;
|
||||
std::cerr << " Error: cannot read file " << input_file << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
std::cout << " Done. " << points.size() << " points. Time: " << t.time() << " sec." << std::endl;
|
||||
}
|
||||
else if (extension == ".ply") {
|
||||
if (!CGAL::read_ply_points_with_properties(
|
||||
input_stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::make_ply_point_reader(Point_map()),
|
||||
CGAL::make_ply_normal_reader(Normal_map()),
|
||||
std::make_pair(Plane_index_map(), CGAL::PLY_property<int>("segment_index"))))
|
||||
if (!CGAL::read_ply_points_with_properties(
|
||||
input_stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::make_ply_point_reader(Point_map()),
|
||||
CGAL::make_ply_normal_reader(Normal_map()),
|
||||
std::make_pair(Plane_index_map(), CGAL::PLY_property<int>("segment_index"))))
|
||||
{
|
||||
std::cerr << " Error: cannot read file " << input_file << std::endl;
|
||||
std::cerr << " Error: cannot read file " << input_file << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
std::cout << " Done. " << points.size() << " points. Time: " << t.time() << " sec." << std::endl;
|
||||
|
||||
int max_plane_index = 0;
|
||||
for (std::size_t i = 0; i < points.size(); ++i) {
|
||||
int plane_index = points[i].template get<2>();
|
||||
for (std::size_t i = 0; i < points.size(); ++i) {
|
||||
int plane_index = points[i].template get<2>();
|
||||
if (plane_index > max_plane_index)
|
||||
max_plane_index = plane_index;
|
||||
}
|
||||
|
|
@ -106,12 +106,12 @@ int reconstruct(const std::string& input_file, bool force_extract_planes)
|
|||
// Shape detection
|
||||
Efficient_ransac ransac;
|
||||
ransac.set_input(points);
|
||||
ransac.template add_shape_factory<Plane>();
|
||||
ransac.template add_shape_factory<Plane>();
|
||||
|
||||
t.reset();
|
||||
ransac.detect();
|
||||
|
||||
typename Efficient_ransac::Plane_range planes = ransac.planes();
|
||||
typename Efficient_ransac::Plane_range planes = ransac.planes();
|
||||
std::size_t num_planes = planes.size();
|
||||
|
||||
std::cout << " Done. " << num_planes << " planes extracted. Time: " << t.time() << " sec." << std::endl;
|
||||
|
|
@ -121,7 +121,7 @@ int reconstruct(const std::string& input_file, bool force_extract_planes)
|
|||
for (std::size_t i = 0; i < points.size(); ++i) {
|
||||
// Use the get function from the property map that accesses the 3rd element of the tuple.
|
||||
int plane_index = get(shape_index_map, i);
|
||||
points[i].template get<2>() = plane_index;
|
||||
points[i].template get<2>() = plane_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,19 +146,19 @@ int reconstruct(const std::string& input_file, bool force_extract_planes)
|
|||
std::cout << "\t\t\tReconstructing...";
|
||||
t.reset();
|
||||
|
||||
if (!algo.template reconstruct<MIP_Solver>(model)) {
|
||||
if (!algo.template reconstruct<MIP_Solver>(model)) {
|
||||
std::cerr << " Failed: " << algo.error_message() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cout << " Done. Time: " << t.time() << " sec." << std::endl;
|
||||
std::cout << " Done. Time: " << t.time() << " sec. ";
|
||||
|
||||
if (model.is_valid()) {
|
||||
std::cout << "\t\t\tReconstructed model has " << model.number_of_faces() << " faces" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
std::cout << "\tReconstructed model has " << model.number_of_faces() << " faces" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else {
|
||||
std::cout << "\t\t\tReconstructed model is not valid. Reconstruction maybe failed?" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
std::cout << "\tReconstructed model is not valid. Reconstruction maybe failed?" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
#include <CGAL/Kernel_traits.h>
|
||||
#include <CGAL/IO/io.h>
|
||||
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
|
||||
#include <tuple>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
|
|
|||
Loading…
Reference in New Issue