Use the new IO functions in Point_set_3 / PSP_3 examples

This commit is contained in:
Mael Rouxel-Labbé 2020-06-21 15:06:20 +02:00
parent 52d50f7d79
commit 24d2ee9c75
36 changed files with 455 additions and 562 deletions

View File

@ -1,7 +1,8 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3.h> #include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>
#include <CGAL/draw_point_set_3.h> #include <CGAL/draw_point_set_3.h>
#include <fstream> #include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
@ -12,14 +13,12 @@ typedef CGAL::Point_set_3<Point> Point_set;
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
std::ifstream f (argc > 1 ? argv[1] : "data/oni.xyz"); const char* filename = argc > 1 ? argv[1] : "data/oni.xyz";
Point_set point_set; Point_set point_set;
// Reading input in XYZ format if(!CGAL::read_point_set(filename, point_set))
if (!f || !CGAL::read_point_set(f, point_set))
{ {
std::cerr<<"Can't read input file " std::cerr << "Can't read input file " << filename << std::endl;
<<(argc > 1 ? argv[1] : "data/oni.xyz")<< std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -14,12 +14,12 @@ typedef CGAL::Point_set_3<Point> Point_set;
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
std::ifstream f (argc > 1 ? argv[1] : "data/camel.off"); const char* filename = argc > 1 ? argv[1] : "data/camel.off";
Point_set point_set; Point_set point_set;
point_set.add_normal_map(); point_set.add_normal_map();
// Reading input in OFF format // Reading input in OFF format
if (!f || !CGAL::read_point_set(f, point_set.index_back_inserter(), // OutputIterator if(!CGAL::read_point_set(filename, point_set.index_back_inserter(),
CGAL::parameters::point_map(point_set.point_push_map()) CGAL::parameters::point_map(point_set.point_push_map())
.normal_map(point_set.normal_push_map()))) .normal_map(point_set.normal_push_map())))
{ {

View File

@ -35,7 +35,6 @@ int main (int, char**)
for (std::size_t i = 0; i < nb_pts; ++ i) for (std::size_t i = 0; i < nb_pts; ++ i)
point_set.insert (*(generator ++)); point_set.insert (*(generator ++));
// Add normal property and estimate normal values // Add normal property and estimate normal values
point_set.add_normal_map(); point_set.add_normal_map();
CGAL::jet_estimate_normals<CGAL::Sequential_tag> CGAL::jet_estimate_normals<CGAL::Sequential_tag>
@ -44,7 +43,6 @@ int main (int, char**)
point_set.parameters(). // Named parameters provided by Point_set_3 point_set.parameters(). // Named parameters provided by Point_set_3
degree_fitting(2)); // additional named parameter specific to jet_estimate_normals degree_fitting(2)); // additional named parameter specific to jet_estimate_normals
// Simplify point set // Simplify point set
CGAL::grid_simplify_point_set CGAL::grid_simplify_point_set
(point_set, (point_set,

View File

@ -23,8 +23,8 @@ void print_point_set (const Point_set& point_set)
boost::tie (intensity, boost::tuples::ignore) = point_set.property_map<FT>("intensity"); boost::tie (intensity, boost::tuples::ignore) = point_set.property_map<FT>("intensity");
std::cerr << "Content of point set:" << std::endl; std::cerr << "Content of point set:" << std::endl;
for (Point_set::const_iterator it = point_set.begin(); for (Point_set::const_iterator it = point_set.begin(); it != point_set.end(); ++ it)
it != point_set.end(); ++ it) {
std::cerr << "* Point " << point_set.point(*it) // or point_set[it] std::cerr << "* Point " << point_set.point(*it) // or point_set[it]
<< " with color [" << (int)(color[*it][0]) << " with color [" << (int)(color[*it][0])
<< " " << (int)(color[*it][1]) << " " << (int)(color[*it][1])
@ -32,7 +32,7 @@ void print_point_set (const Point_set& point_set)
<< "] and intensity " << intensity[*it] << "] and intensity " << intensity[*it]
<< std::endl; << std::endl;
} }
}
int main (int, char**) int main (int, char**)
{ {

View File

@ -1,6 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3.h> #include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@ -19,9 +19,10 @@ int main (int argc, char** argv)
Point_set point_set; Point_set point_set;
if (!f || !CGAL::read_PLY (f, point_set)) // same as `f >> point_set` if(!CGAL::read_PLY (f, point_set)) // same as `f >> point_set`
{ {
std::cerr << "Can't read input file " << std::endl; std::cerr << "Can't read input file " << std::endl;
return EXIT_FAILURE;
} }
// Shows which properties are defined // Shows which properties are defined

View File

@ -14,7 +14,7 @@ typedef CGAL::Point_set_3<Point> Point_set;
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
const char* fname (argc > 1 ? argv[1] : "data/oni.xyz"); const char* fname = argc > 1 ? argv[1] : "data/oni.xyz";
Point_set point_set; Point_set point_set;
@ -37,12 +37,8 @@ int main (int argc, char** argv)
} }
// Writing result in OFF format // Writing result in OFF format
std::ofstream out("normalized_normals.off"); if(!CGAL::write_OFF("normalized_normals.off", point_set, CGAL::parameters::stream_precision(17)))
out.precision(17);
if (!out || !CGAL::write_OFF (out, point_set))
{
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -32,8 +32,7 @@ void print_point_set (const Point_set& ps, const char* msg)
{ {
Point_set::Property_map<int> intensity; Point_set::Property_map<int> intensity;
bool has_intensity; bool has_intensity;
boost::tie (intensity, has_intensity) boost::tie (intensity, has_intensity) = ps.property_map<int>("intensity");
= ps.property_map<int>("intensity");
std::cerr << msg << std::endl; std::cerr << msg << std::endl;
for (Point_set::const_iterator it = ps.begin(); it != ps.end(); ++ it) for (Point_set::const_iterator it = ps.begin(); it != ps.end(); ++ it)
@ -47,7 +46,6 @@ void print_point_set (const Point_set& ps, const char* msg)
} }
} }
int main (int, char**) int main (int, char**)
{ {
Point_set ps1, ps2; Point_set ps1, ps2;

View File

@ -210,13 +210,13 @@ descriptor
- a tuple consisting of a property map, a functor to construct the - a tuple consisting of a property map, a functor to construct the
objects wanted and multiple %PLY/%LAS property descriptors objects wanted and multiple %PLY/%LAS property descriptors
Output functions `write_ply_points_with_properties()` and Output functions `write_PLY_with_properties()` and
`write_las_points_with_properties()` work similarly. `write_LAS_with_properties()` work similarly.
\subsubsection Point_set_processing_3Example_ply_write PLY Writing Example \subsubsection Point_set_processing_3Example_ply_write PLY Writing Example
The following example shows how to call The following example shows how to call
`write_ply_points_with_properties()` to write a point set with points, `write_PLY_with_properties()` to write a point set with points,
RGB colors and intensity. Notice that in order to write a complex RGB colors and intensity. Notice that in order to write a complex
object, users need to provide an overload of `CGAL::Output_rep`. object, users need to provide an overload of `CGAL::Output_rep`.

View File

@ -21,13 +21,13 @@ typedef CGAL::Parallel_if_available_tag Concurrency_tag;
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
const char* fname = (argc>1)?argv[1]:"data/sphere_20k.xyz"; const char* fname = (argc>1)?argv[1]:"data/sphere_20k.xyz";
// Reads a .xyz point set file in points. // Reads a .xyz point set file in points.
// As the point is the second element of the tuple (that is with index 1) // As the point is the second element of the tuple (that is with index 1)
// we use a property map that accesses the 1st element of the tuple. // we use a property map that accesses the 1st element of the tuple.
std::vector<IndexedPointWithColorTuple> points; std::vector<IndexedPointWithColorTuple> points;
if (!CGAL::read_points( if (!CGAL::read_points(fname, std::back_inserter(points),
fname, std::back_inserter(points),
CGAL::parameters::point_map(CGAL::Nth_of_tuple_property_map<1, IndexedPointWithColorTuple>()))) CGAL::parameters::point_map(CGAL::Nth_of_tuple_property_map<1, IndexedPointWithColorTuple>())))
{ {
std::cerr << "Error: cannot read file " << fname << std::endl; std::cerr << "Error: cannot read file " << fname << std::endl;

View File

@ -48,20 +48,17 @@ int main(int argc, char*argv[])
CGAL::bilateral_smooth_point_set <Concurrency_tag>( CGAL::bilateral_smooth_point_set <Concurrency_tag>(
points, points,
k, k,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()). .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())
sharpness_angle (sharpness_angle)); .sharpness_angle (sharpness_angle));
} }
//// Save point set. //// Save point set.
std::ofstream out(output_filename); if(!CGAL::write_XYZ(output_filename, points,
out.precision(17);
if (!out || !CGAL::write_XYZ(out, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()) CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()))) .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())
{ .stream_precision(17)))
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -60,7 +60,6 @@ struct Progress_to_std_cerr_callback
} }
}; };
int main (int argc, char* argv[]) int main (int argc, char* argv[])
{ {
int N = (argc > 1) ? boost::lexical_cast<int>(argv[1]) : 1000; int N = (argc > 1) ? boost::lexical_cast<int>(argv[1]) : 1000;
@ -74,21 +73,16 @@ int main (int argc, char* argv[])
// Compute average spacing // Compute average spacing
FT average_spacing = CGAL::compute_average_spacing<Concurrency_tag> FT average_spacing = CGAL::compute_average_spacing<Concurrency_tag>
(points, 6, (points, 6,
CGAL::parameters::callback CGAL::parameters::callback(Progress_to_std_cerr_callback("Computing average spacing")));
(Progress_to_std_cerr_callback("Computing average spacing")));
// Simplify on a grid with a size of twice the average spacing // Simplify on a grid with a size of twice the average spacing
points.erase(CGAL::grid_simplify_point_set points.erase(CGAL::grid_simplify_point_set(points, 2. * average_spacing,
(points, 2. * average_spacing, CGAL::parameters::callback(Progress_to_std_cerr_callback("Grid simplification"))),
CGAL::parameters::callback
(Progress_to_std_cerr_callback("Grid simplification"))),
points.end()); points.end());
// Smooth simplified point set // Smooth simplified point set
CGAL::jet_smooth_point_set<Concurrency_tag> CGAL::jet_smooth_point_set<Concurrency_tag>(points, 6,
(points, 6, CGAL::parameters::callback(Progress_to_std_cerr_callback("Jet smoothing")));
CGAL::parameters::callback
(Progress_to_std_cerr_callback("Jet smoothing")));
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -8,6 +8,7 @@
#include <CGAL/Real_timer.h> #include <CGAL/Real_timer.h>
#include <fstream> #include <fstream>
#include <iostream>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_3 = Kernel::Point_3; using Point_3 = Kernel::Point_3;
@ -35,8 +36,8 @@ int main (int argc, char** argv)
t.start(); t.start();
std::size_t nb_clusters std::size_t nb_clusters
= CGAL::cluster_point_set(points, cluster_map, = CGAL::cluster_point_set(points, cluster_map,
points.parameters().neighbor_radius(spacing). points.parameters().neighbor_radius(spacing)
adjacencies (std::back_inserter (adjacencies))); .adjacencies(std::back_inserter(adjacencies)));
t.stop(); t.stop();
std::cerr << "Found " << nb_clusters << " clusters with " << adjacencies.size() std::cerr << "Found " << nb_clusters << " clusters with " << adjacencies.size()
<< " adjacencies in " << t.time() << " seconds" << std::endl; << " adjacencies in " << t.time() << " seconds" << std::endl;

View File

@ -52,14 +52,11 @@ int main(int argc, char* argv[])
number_of_output_points(number_of_output_points)); number_of_output_points(number_of_output_points));
// Saves point set. // Saves point set.
std::ofstream out(output_filename); if(!CGAL::write_points(output_filename, points,
out.precision(17);
if (!out || !CGAL::write_XYZ(out, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()) CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()))) .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())
{ .stream_precision(17)))
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -7,7 +7,6 @@
#include <vector> #include <vector>
#include <fstream> #include <fstream>
// Types // Types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point; typedef Kernel::Point_3 Point;
@ -19,7 +18,8 @@ typedef std::vector<PointVectorPair> PointList;
typedef std::array<double,6> Covariance; typedef std::array<double,6> Covariance;
int main (int , char**) { int main (int , char**)
{
// Reads a .xyz point set file in points[]. // Reads a .xyz point set file in points[].
std::list<PointVectorPair> points; std::list<PointVectorPair> points;
if(!CGAL::read_points("data/fandisk.off", if(!CGAL::read_points("data/fandisk.off",

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/grid_simplify_point_set.h> #include <CGAL/grid_simplify_point_set.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_points.h>
@ -22,12 +23,10 @@ int main(int argc, char*argv[])
// simplification by clustering using erase-remove idiom // simplification by clustering using erase-remove idiom
double cell_size = 0.001; double cell_size = 0.001;
points.erase(CGAL::grid_simplify_point_set(points, cell_size), points.erase(CGAL::grid_simplify_point_set(points, cell_size), points.end());
points.end());
// Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity // Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity
std::vector<Point>(points).swap(points); std::vector<Point>(points).swap(points);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/grid_simplify_point_set.h> #include <CGAL/grid_simplify_point_set.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
@ -19,7 +20,8 @@ int main(int argc, char*argv[])
std::ifstream stream(fname); std::ifstream stream(fname);
Point p; Point p;
Vector v; Vector v;
while(stream >> p >> v){ while(stream >> p >> v)
{
points.push_back(p); points.push_back(p);
normals.push_back(v); normals.push_back(v);
} }

View File

@ -15,7 +15,7 @@ typedef Kernel::Point_3 Point;
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
// Reads a .xyz point set file in points[]. // Reads a point set file in points[].
std::vector<Point> points; std::vector<Point> points;
const char* fname = (argc>1)?argv[1]:"data/oni.xyz"; const char* fname = (argc>1)?argv[1]:"data/oni.xyz";
if(!CGAL::read_points(fname, std::back_inserter(points))) if(!CGAL::read_points(fname, std::back_inserter(points)))
@ -23,14 +23,15 @@ int main(int argc, char*argv[])
std::cerr << "Error: cannot read file " << fname << std::endl; std::cerr << "Error: cannot read file " << fname << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::cout << "Read " << points.size () << " point(s)" << std::endl; std::cout << "Read " << points.size () << " point(s)" << std::endl;
CGAL::Timer task_timer; task_timer.start(); CGAL::Timer task_timer; task_timer.start();
// simplification by clustering using erase-remove idiom // simplification by clustering using erase-remove idiom
points.erase(CGAL::hierarchy_simplify_point_set(points, points.erase(CGAL::hierarchy_simplify_point_set(points,
CGAL::parameters::size(100). // Max cluster size CGAL::parameters::size(100)// Max cluster size
maximum_variation(0.01)), // Max surface variation .maximum_variation(0.01)), // Max surface variation
points.end()); points.end());
std::size_t memory = CGAL::Memory_sizer().virtual_size(); std::size_t memory = CGAL::Memory_sizer().virtual_size();
@ -39,9 +40,7 @@ int main(int argc, char*argv[])
<< task_timer.time() << " seconds, " << task_timer.time() << " seconds, "
<< (memory>>20) << " Mib allocated." << std::endl; << (memory>>20) << " Mib allocated." << std::endl;
std::ofstream f ("out.xyz"); CGAL::write_points("out.xyz", points, CGAL::parameters::stream_precision(17));
f.precision(17);
CGAL::write_XYZ (f, points);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -30,4 +30,3 @@ int main(void)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -9,19 +9,19 @@
//---------------------------------------------------------- //----------------------------------------------------------
// normal_estimation file_in file_out [options] // normal_estimation file_in file_out [options]
// CGAL
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Memory_sizer.h>
#include <CGAL/Timer.h>
// This package // This package
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/pca_estimate_normals.h> #include <CGAL/pca_estimate_normals.h>
#include <CGAL/jet_estimate_normals.h> #include <CGAL/jet_estimate_normals.h>
#include <CGAL/vcm_estimate_normals.h> #include <CGAL/vcm_estimate_normals.h>
#include <CGAL/mst_orient_normals.h> #include <CGAL/mst_orient_normals.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h> // CGAL
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Memory_sizer.h>
#include <CGAL/Timer.h>
#include <utility> // defines std::pair #include <utility> // defines std::pair
#include <vector> #include <vector>
@ -29,7 +29,6 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Types // Types
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -69,7 +68,6 @@ void run_pca_estimate_normals(PointList& points, // input points + output normal
CGAL::parameters::point_map (CGAL::First_of_pair_property_map<PointVectorPair>()). CGAL::parameters::point_map (CGAL::First_of_pair_property_map<PointVectorPair>()).
normal_map (CGAL::Second_of_pair_property_map<PointVectorPair>())); normal_map (CGAL::Second_of_pair_property_map<PointVectorPair>()));
std::size_t memory = CGAL::Memory_sizer().virtual_size(); std::size_t memory = CGAL::Memory_sizer().virtual_size();
std::cerr << "done: " << task_timer.time() << " seconds, " std::cerr << "done: " << task_timer.time() << " seconds, "
<< (memory>>20) << " Mb allocated" << (memory>>20) << " Mb allocated"
@ -247,21 +245,8 @@ int main(int argc, char * argv[])
std::cerr << "Open " << input_filename << " for reading..." << std::endl; std::cerr << "Open " << input_filename << " for reading..." << std::endl;
// If OFF file format // If OFF file format
bool success = false; if(!CGAL::read_points(input_filename.c_str(), std::back_inserter(points),
std::string extension = input_filename.substr(input_filename.find_last_of('.')); CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())))
if (extension == ".off" || extension == ".OFF")
{
success = CGAL::read_points(input_filename.c_str(), std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()));
}
// If XYZ file format
else if (extension == ".xyz" || extension == ".XYZ" ||
extension == ".pwn" || extension == ".PWN")
{
success = CGAL::read_points(input_filename.c_str(), std::back_inserter(points),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()));
}
if (!success)
{ {
std::cerr << "Error: cannot read file " << input_filename << std::endl; std::cerr << "Error: cannot read file " << input_filename << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -306,22 +291,10 @@ int main(int argc, char * argv[])
std::cerr << "Write file " << output_filename << std::endl << std::endl; std::cerr << "Write file " << output_filename << std::endl << std::endl;
// If XYZ file format if(!CGAL::write_points(output_filename, points,
/*std::string*/ extension = output_filename.substr(output_filename.find_last_of('.'));
if (extension == ".xyz" || extension == ".XYZ" ||
extension == ".pwn" || extension == ".PWN")
{
std::ofstream stream(output_filename.c_str());
stream.precision(17);
if (!stream || !CGAL::write_XYZ(stream, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()) CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
.normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()))) .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())
{ .stream_precision(17)))
std::cerr << "Error: cannot write file " << output_filename << std::endl;
return EXIT_FAILURE;
}
}
else
{ {
std::cerr << "Error: cannot write file " << output_filename << std::endl; std::cerr << "Error: cannot write file " << output_filename << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/compute_average_spacing.h> #include <CGAL/compute_average_spacing.h>
#include <CGAL/pca_estimate_normals.h> #include <CGAL/pca_estimate_normals.h>
#include <CGAL/mst_orient_normals.h> #include <CGAL/mst_orient_normals.h>
@ -23,6 +24,7 @@ typedef CGAL::Parallel_if_available_tag Concurrency_tag;
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
const char* fname = (argc>1) ? argv[1] : "data/sphere_1k.xyz"; const char* fname = (argc>1) ? argv[1] : "data/sphere_1k.xyz";
// Reads a .xyz point set file in points[]. // Reads a .xyz point set file in points[].
std::list<PointVectorPair> points; std::list<PointVectorPair> points;
if(!CGAL::read_points(fname, if(!CGAL::read_points(fname,
@ -50,16 +52,16 @@ int main(int argc, char*argv[])
CGAL::pca_estimate_normals<Concurrency_tag> CGAL::pca_estimate_normals<Concurrency_tag>
(points, (points,
0, // when using a neighborhood radius, K=0 means no limit on the number of neighbors returns 0, // when using a neighborhood radius, K=0 means no limit on the number of neighbors returns
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()). .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())
neighbor_radius(2. * spacing)); // use 2*spacing as neighborhood radius .neighbor_radius(2. * spacing)); // use 2*spacing as neighborhood radius
} }
else // Use a fixed number of neighbors else // Use a fixed number of neighbors
{ {
CGAL::pca_estimate_normals<Concurrency_tag> CGAL::pca_estimate_normals<Concurrency_tag>
(points, nb_neighbors, (points, nb_neighbors,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())); .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
} }
// Orients normals. // Orients normals.
@ -67,8 +69,8 @@ int main(int argc, char*argv[])
// as well as property maps to access each point's position and normal. // as well as property maps to access each point's position and normal.
std::list<PointVectorPair>::iterator unoriented_points_begin = std::list<PointVectorPair>::iterator unoriented_points_begin =
CGAL::mst_orient_normals(points, nb_neighbors, CGAL::mst_orient_normals(points, nb_neighbors,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())); .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()));
// Optional: delete points with an unoriented normal // Optional: delete points with an unoriented normal
// if you plan to call a reconstruction algorithm that expects oriented normals. // if you plan to call a reconstruction algorithm that expects oriented normals.
@ -76,4 +78,3 @@ int main(int argc, char*argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -43,7 +43,6 @@ struct MyLess {
} }
}; };
// In this example we have a function that only operates on the point part. // In this example we have a function that only operates on the point part.
// It sorts them lexicographically. // It sorts them lexicographically.
@ -54,7 +53,6 @@ void process_point_set(Iterator beg, Iterator end, PointPMap pmap)
std::sort(beg,end,less); std::sort(beg,end,less);
} }
// We can call it just with points. Then interally we use a property map // We can call it just with points. Then interally we use a property map
// that maps point iterators on points. // that maps point iterators on points.
@ -67,8 +65,6 @@ void process_point_set(Iterator beg, Iterator end)
); );
} }
// Here comes a function that changes the orientation and the normal // Here comes a function that changes the orientation and the normal
template <typename Iterator, typename OrientationPMap, typename NormalPMap > template <typename Iterator, typename OrientationPMap, typename NormalPMap >
@ -84,8 +80,6 @@ void orient_normals(Iterator beg, Iterator end, OrientationPMap orient_pmap, Nor
} }
} }
int main() int main()
{ {
CGAL::set_pretty_mode(std::cout); CGAL::set_pretty_mode(std::cout);
@ -93,29 +87,22 @@ int main()
// Here we run it on plain points. No need for a property map // Here we run it on plain points. No need for a property map
{ {
std::vector<Point_3> points; std::vector<Point_3> points;
process_point_set(points.begin(), points.end()); process_point_set(points.begin(), points.end());
} }
// Here we run it on points with normal vectors stored in a std::pair. // Here we run it on points with normal vectors stored in a std::pair.
// We use a property map that accesses pair::first. // We use a property map that accesses pair::first.
{ {
std::vector<PointVectorPair> points; std::vector<PointVectorPair> points;
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++)
points.push_back(std::make_pair(Point_3(9-i,0,0), Vector_3(i,0,0))); points.push_back(std::make_pair(Point_3(9-i,0,0), Vector_3(i,0,0)));
}
process_point_set(points.begin(), process_point_set(points.begin(), points.end(), CGAL::First_of_pair_property_map<PointVectorPair>());
points.end(),
CGAL::First_of_pair_property_map<PointVectorPair>());
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++)
std::cout << points[i].first << "\t" << points[i].second << std::endl; std::cout << points[i].first << "\t" << points[i].second << std::endl;
} }
}
// Here we run it on tuples. To see the interest I made up my own // Here we run it on tuples. To see the interest I made up my own
// data type = index, followed by the point, followed by a Boolean // data type = index, followed by the point, followed by a Boolean
@ -128,49 +115,44 @@ int main()
typedef boost::tuple<int, Point_3, bool, Vector_3> IndexedPointWithOrientableNormalTuple; typedef boost::tuple<int, Point_3, bool, Vector_3> IndexedPointWithOrientableNormalTuple;
std::vector<IndexedPointWithOrientableNormalTuple> points; std::vector<IndexedPointWithOrientableNormalTuple> points;
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++)
{
double x = (i%2)?i:-i; double x = (i%2)?i:-i;
points.push_back(boost::make_tuple(i,Point_3(9-i,0,0), false, Vector_3(x,0,0))); points.push_back(boost::make_tuple(i,Point_3(9-i,0,0), false, Vector_3(x,0,0)));
} }
process_point_set(points.begin(), process_point_set(points.begin(), points.end(), CGAL::Nth_of_tuple_property_map<1,IndexedPointWithOrientableNormalTuple>());
points.end(),
CGAL::Nth_of_tuple_property_map<1,IndexedPointWithOrientableNormalTuple>());
std::cout << boost::tuples::set_open('[') << boost::tuples::set_close(']') << boost::tuples::set_delimiter(','); std::cout << boost::tuples::set_open('[') << boost::tuples::set_close(']') << boost::tuples::set_delimiter(',');
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++)
std::cout << points[i] << std::endl; std::cout << points[i] << std::endl;
}
//We keep the sequence in order, but determine the normal and if it is different from zero set the Boolean to true //We keep the sequence in order, but determine the normal and if it is different from zero set the Boolean to true
orient_normals(points.begin(), orient_normals(points.begin(), points.end(),
points.end(),
CGAL::make_nth_of_tuple_property_map<2>(IndexedPointWithOrientableNormalTuple()), CGAL::make_nth_of_tuple_property_map<2>(IndexedPointWithOrientableNormalTuple()),
CGAL::make_nth_of_tuple_property_map<3>(IndexedPointWithOrientableNormalTuple())); CGAL::make_nth_of_tuple_property_map<3>(IndexedPointWithOrientableNormalTuple()));
std::cout << "\nAfter orient_normals\n"; std::cout << "\nAfter orient_normals\n";
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++)
std::cout << points[i] << std::endl; std::cout << points[i] << std::endl;
} }
}
// same test with std::tuple // same test with std::tuple
{ {
typedef std::tuple<int, Point_3, bool, Vector_3> IndexedPointWithOrientableNormalTuple; typedef std::tuple<int, Point_3, bool, Vector_3> IndexedPointWithOrientableNormalTuple;
std::vector<IndexedPointWithOrientableNormalTuple> points; std::vector<IndexedPointWithOrientableNormalTuple> points;
for(int i = 0; i < 10; i++){ for(int i = 0; i < 10; i++)
{
double x = (i%2)?i:-i; double x = (i%2)?i:-i;
points.push_back(std::make_tuple(i,Point_3(9-i,0,0), false, Vector_3(x,0,0))); points.push_back(std::make_tuple(i,Point_3(9-i,0,0), false, Vector_3(x,0,0)));
} }
process_point_set(points.begin(), process_point_set(points.begin(), points.end(),
points.end(),
CGAL::Nth_of_tuple_property_map<1,IndexedPointWithOrientableNormalTuple>()); CGAL::Nth_of_tuple_property_map<1,IndexedPointWithOrientableNormalTuple>());
orient_normals(points.begin(), orient_normals(points.begin(), points.end(),
points.end(),
CGAL::make_nth_of_tuple_property_map<2>(IndexedPointWithOrientableNormalTuple()), CGAL::make_nth_of_tuple_property_map<2>(IndexedPointWithOrientableNormalTuple()),
CGAL::make_nth_of_tuple_property_map<3>(IndexedPointWithOrientableNormalTuple())); CGAL::make_nth_of_tuple_property_map<3>(IndexedPointWithOrientableNormalTuple()));
} }

View File

@ -1,7 +1,8 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/random_simplify_point_set.h> #include <CGAL/random_simplify_point_set.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h> #include <CGAL/IO/write_points.h>
#include <vector> #include <vector>
#include <fstream> #include <fstream>
@ -14,7 +15,8 @@ typedef Kernel::Point_3 Point;
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
const char* fname = (argc>1) ? argv[1] : "data/oni.xyz"; const char* fname = (argc>1) ? argv[1] : "data/oni.xyz";
// Reads a .xyz point set file in points[].
// Reads a point set file in points[].
std::vector<Point> points; std::vector<Point> points;
if(!CGAL::read_points(fname, std::back_inserter(points))) if(!CGAL::read_points(fname, std::back_inserter(points)))
{ {
@ -24,22 +26,15 @@ int main(int argc, char*argv[])
// Randomly simplifies using erase-remove idiom // Randomly simplifies using erase-remove idiom
const double removed_percentage = 97.0; // percentage of points to remove const double removed_percentage = 97.0; // percentage of points to remove
points.erase(CGAL::random_simplify_point_set(points, removed_percentage), points.erase(CGAL::random_simplify_point_set(points, removed_percentage), points.end());
points.end());
// Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity // Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity
std::vector<Point>(points).swap(points); std::vector<Point>(points).swap(points);
// Saves point set. // Saves point set.
std::ofstream out((argc>2)?argv[2]:"Three_lady_copy.xyz"); const std::string output_filename = (argc>2) ? argv[2] : "Three_lady_copy.xyz";
out.precision(17); if(!CGAL::write_points(output_filename, points, CGAL::parameters::stream_precision(17)))
if (!out ||
!CGAL::write_XYZ(
out, points))
{
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,6 +1,7 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_las_points.h>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -21,13 +22,9 @@ int main(int argc, char*argv[])
std::vector<PointWithColor> points; // store points std::vector<PointWithColor> points; // store points
std::ifstream in(fname, std::ios_base::binary); std::ifstream in(fname, std::ios_base::binary);
if (!in || if(!CGAL::read_LAS_with_properties(in, std::back_inserter (points),
!CGAL::read_LAS_with_properties
(in,
std::back_inserter (points),
CGAL::make_las_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()), CGAL::make_las_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()),
std::make_tuple std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
(CGAL::Second_of_pair_property_map<PointWithColor>(),
CGAL::Construct_array(), CGAL::Construct_array(),
CGAL::LAS_property::R(), CGAL::LAS_property::R(),
CGAL::LAS_property::G(), CGAL::LAS_property::G(),

View File

@ -1,6 +1,7 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_ply_points.h>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -23,25 +24,19 @@ typedef CGAL::Nth_of_tuple_property_map<3, PNCI> Intensity_map;
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
const char* fname = (argc>1) ? argv[1] : "data/colors.ply"; const char* fname = (argc>1) ? argv[1] : "data/colors.ply";
// Reads a .ply point set file with normal vectors and colors
// Reads a .ply point set file with normal vectors and colors
std::vector<PNCI> points; // store points std::vector<PNCI> points; // store points
std::ifstream in(fname); std::ifstream in(fname);
if(!CGAL::read_PLY_with_properties(in, std::back_inserter(points),
if (!in ||
!CGAL::read_PLY_with_properties
(in,
std::back_inserter (points),
CGAL::make_ply_point_reader(Point_map()), CGAL::make_ply_point_reader(Point_map()),
std::make_pair (Intensity_map(), std::make_pair(Intensity_map(), CGAL::PLY_property<int>("intensity")),
CGAL::PLY_property<int>("intensity")),
std::make_tuple(Color_map(), std::make_tuple(Color_map(),
CGAL::Construct_array(), CGAL::Construct_array(),
CGAL::PLY_property<unsigned char>("red"), CGAL::PLY_property<unsigned char>("red"),
CGAL::PLY_property<unsigned char>("green"), CGAL::PLY_property<unsigned char>("green"),
CGAL::PLY_property<unsigned char>("blue")), CGAL::PLY_property<unsigned char>("blue")),
CGAL::make_ply_normal_reader (Normal_map()) CGAL::make_ply_normal_reader(Normal_map())))
))
{ {
std::cerr << "Error: cannot read file " << fname << std::endl; std::cerr << "Error: cannot read file " << fname << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -54,7 +49,8 @@ int main(int argc, char*argv[])
const Vector& n = get<1>(points[i]); const Vector& n = get<1>(points[i]);
const Color& c = get<2>(points[i]); const Color& c = get<2>(points[i]);
int I = get<3>(points[i]); int I = get<3>(points[i]);
std::cerr << "Point (" << p << ") with normal (" << n std::cerr << "Point (" << p
<< ") with normal (" << n
<< "), color (" << int(c[0]) << " " << int(c[1]) << " " << int(c[2]) << "), color (" << int(c[0]) << " " << int(c[1]) << " " << int(c[2])
<< ") and intensity " << I << std::endl; << ") and intensity " << I << std::endl;
} }

View File

@ -1,6 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_xyz_points.h>
#include <CGAL/IO/write_xyz_points.h> #include <CGAL/IO/write_xyz_points.h>
#include <utility> // defines std::pair #include <utility> // defines std::pair
@ -24,10 +24,10 @@ int main(int argc, char*argv[])
// over points and as well as property maps to access each // over points and as well as property maps to access each
// point position and normal. // point position and normal.
std::vector<Pwn> points; std::vector<Pwn> points;
if (!CGAL::read_points(fname, if(!CGAL::read_XYZ(fname,
std::back_inserter(points), std::back_inserter(points),
CGAL::parameters::point_map (CGAL::First_of_pair_property_map<Pwn>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>())
normal_map (CGAL::Second_of_pair_property_map<Pwn>()))) .normal_map(CGAL::Second_of_pair_property_map<Pwn>())))
{ {
std::cerr << "Error: cannot read file " << fname << std::endl; std::cerr << "Error: cannot read file " << fname << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -36,16 +36,11 @@ int main(int argc, char*argv[])
// Saves point set. // Saves point set.
// Note: write_XYZ() requires property maps to access each // Note: write_XYZ() requires property maps to access each
// point position and normal. // point position and normal.
std::ofstream out("oni_copy.xyz"); if(!CGAL::write_XYZ("oni_copy.xyz", points,
out.precision(17); CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>())
if (!out || .normal_map(CGAL::Second_of_pair_property_map<Pwn>())
!CGAL::write_XYZ( .stream_precision(17)))
out, points,
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>()).
normal_map(CGAL::Second_of_pair_property_map<Pwn>())))
{
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -26,16 +26,16 @@ int main(int argc, const char** argv)
std::vector<Pwn> pwns1, pwns2; std::vector<Pwn> pwns1, pwns2;
if(!CGAL::read_points(fname1, std::back_inserter(pwns1), if(!CGAL::read_points(fname1, std::back_inserter(pwns1),
CGAL::parameters::point_map (CGAL::First_of_pair_property_map<Pwn>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>())
normal_map (Normal_map()))) .normal_map(Normal_map())))
{ {
std::cerr << "Error: cannot read file " << fname1 << std::endl; std::cerr << "Error: cannot read file " << fname1 << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(!CGAL::read_points(fname2, std::back_inserter(pwns2), if(!CGAL::read_points(fname2, std::back_inserter(pwns2),
CGAL::parameters::point_map (Point_map()). CGAL::parameters::point_map(Point_map())
normal_map (Normal_map()))) .normal_map(Normal_map())))
{ {
std::cerr << "Error: cannot read file " << fname2 << std::endl; std::cerr << "Error: cannot read file " << fname2 << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -63,15 +63,11 @@ int main(int argc, const char** argv)
params::point_map(Point_map()) params::point_map(Point_map())
.normal_map(Normal_map())); .normal_map(Normal_map()));
std::ofstream out("pwns2_aligned.ply"); if(!CGAL::write_points("pwns2_aligned.ply", pwns2,
if (!out || CGAL::parameters::point_map(Point_map())
!CGAL::write_PLY( .normal_map(Normal_map())
out, pwns2, .stream_precision(17)))
CGAL::parameters::point_map(Point_map()).
normal_map(Normal_map())))
{
return EXIT_FAILURE; return EXIT_FAILURE;
}
std::cout << "Registration score: " << score << ".\n" std::cout << "Registration score: " << score << ".\n"
<< "Transformed version of " << fname2 << "Transformed version of " << fname2

View File

@ -1,6 +1,7 @@
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_ply_points.h> #include <CGAL/IO/write_points.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/Aff_transformation_3.h> #include <CGAL/Aff_transformation_3.h>
@ -29,16 +30,16 @@ int main(int argc, const char** argv)
std::vector<Pwn> pwns1, pwns2; std::vector<Pwn> pwns1, pwns2;
if(!CGAL::read_points(fname1, std::back_inserter(pwns1), if(!CGAL::read_points(fname1, std::back_inserter(pwns1),
CGAL::parameters::point_map (CGAL::First_of_pair_property_map<Pwn>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>())
normal_map (Normal_map()))) .normal_map (Normal_map())))
{ {
std::cerr << "Error: cannot read file " << fname1 << std::endl; std::cerr << "Error: cannot read file " << fname1 << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(!CGAL::read_points(fname2, std::back_inserter(pwns2), if(!CGAL::read_points(fname2, std::back_inserter(pwns2),
CGAL::parameters::point_map (Point_map()). CGAL::parameters::point_map(Point_map())
normal_map (Normal_map()))) .normal_map(Normal_map())))
{ {
std::cerr << "Error: cannot read file " << fname2 << std::endl; std::cerr << "Error: cannot read file " << fname2 << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -51,8 +52,7 @@ int main(int argc, const char** argv)
CGAL::OpenGR::compute_registration_transformation CGAL::OpenGR::compute_registration_transformation
(pwns1, pwns2, (pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map()), params::point_map(Point_map()).normal_map(Normal_map()),
params::point_map(Point_map()).normal_map(Normal_map())) params::point_map(Point_map()).normal_map(Normal_map())));
);
std::cerr << "Computing registration transformation using PointMatcher ICP, " std::cerr << "Computing registration transformation using PointMatcher ICP, "
<< "taking transformation computed by OpenGR Super4PCS as initial transformation.." << std::endl; << "taking transformation computed by OpenGR Super4PCS as initial transformation.." << std::endl;
@ -62,15 +62,11 @@ int main(int argc, const char** argv)
CGAL::pointmatcher::register_point_sets CGAL::pointmatcher::register_point_sets
(pwns1, pwns2, (pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map()), params::point_map(Point_map()).normal_map(Normal_map()),
params::point_map(Point_map()).normal_map(Normal_map()) params::point_map(Point_map()).normal_map(Normal_map()).transformation(res));
.transformation(res));
std::ofstream out("pwns2_aligned.ply"); if(!CGAL::write_points("pwns2_aligned.ply", pwns2,
if (!out || CGAL::parameters::point_map(Point_map())
!CGAL::write_PLY( .normal_map(Normal_map())))
out, pwns2,
CGAL::parameters::point_map(Point_map()).
normal_map(Normal_map())))
{ {
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -29,16 +29,16 @@ int main(int argc, const char** argv)
std::vector<Pwn> pwns1, pwns2; std::vector<Pwn> pwns1, pwns2;
if(!CGAL::read_points(fname1, std::back_inserter(pwns1), if(!CGAL::read_points(fname1, std::back_inserter(pwns1),
CGAL::parameters::point_map (CGAL::First_of_pair_property_map<Pwn>()). CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>())
normal_map (Normal_map()))) .normal_map(Normal_map())))
{ {
std::cerr << "Error: cannot read file " << fname1 << std::endl; std::cerr << "Error: cannot read file " << fname1 << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if(!CGAL::read_points(fname2, std::back_inserter(pwns2), if(!CGAL::read_points(fname2, std::back_inserter(pwns2),
CGAL::parameters::point_map (Point_map()). CGAL::parameters::point_map(Point_map())
normal_map (Normal_map()))) .normal_map(Normal_map())))
{ {
std::cerr << "Error: cannot read file " << fname2 << std::endl; std::cerr << "Error: cannot read file " << fname2 << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -128,25 +128,20 @@ int main(int argc, const char** argv)
); );
if(converged) if(converged)
{
std::cerr << "Success" << std::endl; std::cerr << "Success" << std::endl;
}
else else
{ {
std::cerr << "Failure" << std::endl; std::cerr << "Failure" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
std::ofstream out("pwns2_aligned.ply"); if(!CGAL::write_points("pwns2_aligned.ply", pwns2,
if (!out || CGAL::parameters::point_map(Point_map()).normal_map(Normal_map())))
!CGAL::write_PLY(
out, pwns2,
CGAL::parameters::point_map(Point_map()).
normal_map(Normal_map())))
{
return EXIT_FAILURE; return EXIT_FAILURE;
}
std::cout << "Transformed version of " << fname2 std::cout << "Transformed version of " << fname2 << " written to pwn2_aligned.ply.\n";
<< " written to pwn2_aligned.ply.\n";
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/compute_average_spacing.h> #include <CGAL/compute_average_spacing.h>
#include <CGAL/remove_outliers.h> #include <CGAL/remove_outliers.h>
@ -15,7 +16,8 @@ typedef Kernel::Point_3 Point;
int main(int argc, char*argv[]) int main(int argc, char*argv[])
{ {
const char* fname = (argc>1)?argv[1]:"data/oni.xyz"; const char* fname = (argc>1)?argv[1]:"data/oni.xyz";
// Reads a .xyz point set file in points[].
// Reads a point set file in points[].
// The Identity_property_map property map can be omitted here as it is the default value. // The Identity_property_map property map can be omitted here as it is the default value.
std::vector<Point> points; std::vector<Point> points;
if(!CGAL::read_points(fname, std::back_inserter(points), if(!CGAL::read_points(fname, std::back_inserter(points),
@ -30,8 +32,7 @@ int main(int argc, char*argv[])
const int nb_neighbors = 24; // considers 24 nearest neighbor points const int nb_neighbors = 24; // considers 24 nearest neighbor points
// Estimate scale of the point set with average spacing // Estimate scale of the point set with average spacing
const double average_spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag> const double average_spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag>(points, nb_neighbors);
(points, nb_neighbors);
////////////////// //////////////////
// FIRST OPTION // // FIRST OPTION //

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/estimate_scale.h> #include <CGAL/estimate_scale.h>
#include <CGAL/Random.h> #include <CGAL/Random.h>

View File

@ -1,6 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/estimate_scale.h> #include <CGAL/estimate_scale.h>
#include <CGAL/jet_smooth_point_set.h> #include <CGAL/jet_smooth_point_set.h>
#include <CGAL/grid_simplify_point_set.h> #include <CGAL/grid_simplify_point_set.h>
@ -21,7 +21,6 @@ typedef Kernel::Point_3 Point_3;
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
const char* fname = (argc>1)?argv[1]:"data/sphere_20k.xyz"; const char* fname = (argc>1)?argv[1]:"data/sphere_20k.xyz";
CGAL::Timer task_timer; CGAL::Timer task_timer;
@ -41,8 +40,7 @@ int main (int argc, char** argv)
task_timer.stop(); task_timer.stop();
// Example: use estimated k as scale for jet smoothing // Example: use estimated k as scale for jet smoothing
CGAL::jet_smooth_point_set<Concurrency_tag> CGAL::jet_smooth_point_set<Concurrency_tag>(points, static_cast<unsigned int>(k_scale));
(points, static_cast<unsigned int>(k_scale));
// estimate range scale // estimate range scale
task_timer.start(); task_timer.start();
@ -50,9 +48,7 @@ int main (int argc, char** argv)
task_timer.stop(); task_timer.stop();
// Example: use estimated range for grid simplification // Example: use estimated range for grid simplification
points.erase (CGAL::grid_simplify_point_set (points, range_scale), points.erase(CGAL::grid_simplify_point_set(points, range_scale), points.end());
points.end());
// print some informations on runtime // print some informations on runtime
std::size_t memory = CGAL::Memory_sizer().virtual_size(); std::size_t memory = CGAL::Memory_sizer().virtual_size();
@ -63,7 +59,6 @@ int main (int argc, char** argv)
std::cout << " * Global K scale: " << k_scale << std::endl; std::cout << " * Global K scale: " << k_scale << std::endl;
std::cout << " * Global range scale: " << range_scale << std::endl; std::cout << " * Global range scale: " << range_scale << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,10 +1,9 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h> #include <CGAL/IO/write_points.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/Shape_detection/Efficient_RANSAC.h> #include <CGAL/Shape_detection/Efficient_RANSAC.h>
#include <CGAL/structure_point_set.h> #include <CGAL/structure_point_set.h>
#include <iostream> #include <iostream>
@ -33,8 +32,8 @@ int main (int argc, char** argv)
if (!CGAL::read_points((argc>1 ? argv[1] : "data/cube.pwn"), if (!CGAL::read_points((argc>1 ? argv[1] : "data/cube.pwn"),
std::back_inserter(points), std::back_inserter(points),
CGAL::parameters::point_map(Point_map()). CGAL::parameters::point_map(Point_map())
normal_map(Normal_map()))) .normal_map(Normal_map())))
{ {
std::cerr << "Error: cannot read file cube.pwn" << std::endl; std::cerr << "Error: cannot read file cube.pwn" << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
@ -56,18 +55,18 @@ int main (int argc, char** argv)
planes, planes,
std::back_inserter(structured_pts), std::back_inserter(structured_pts),
0.015, // epsilon for structuring points 0.015, // epsilon for structuring points
CGAL::parameters::point_map (Point_map()). CGAL::parameters::point_map(Point_map())
normal_map (Normal_map()). .normal_map(Normal_map())
plane_map (CGAL::Shape_detection::Plane_map<Traits>()). .plane_map(CGAL::Shape_detection::Plane_map<Traits>())
plane_index_map (CGAL::Shape_detection::Point_to_shape_index_map<Traits>(points, planes))); .plane_index_map(CGAL::Shape_detection::Point_to_shape_index_map<Traits>(points, planes)));
std::cerr << structured_pts.size () std::cerr << structured_pts.size ()
<< " structured point(s) generated." << std::endl; << " structured point(s) generated." << std::endl;
std::ofstream out ("out.pwn"); CGAL::write_points("out.pwn", structured_pts,
CGAL::write_XYZ (out, structured_pts, CGAL::parameters::point_map(Point_map())
CGAL::parameters::point_map(Point_map()).normal_map(Normal_map())); .normal_map(Normal_map())
out.close(); .stream_precision(17));
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,7 +1,8 @@
#include <CGAL/Simple_cartesian.h> #include <CGAL/Simple_cartesian.h>
#include <CGAL/wlop_simplify_and_regularize_point_set.h> #include <CGAL/wlop_simplify_and_regularize_point_set.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_xyz_points.h> #include <CGAL/IO/write_points.h>
#include <vector> #include <vector>
#include <fstream> #include <fstream>
@ -25,7 +26,6 @@ int main(int argc, char** argv)
if(!CGAL::read_points(input_filename, std::back_inserter(points))) if(!CGAL::read_points(input_filename, std::back_inserter(points)))
{ {
std::cerr << "Error: cannot read file " << input_filename << std::endl; std::cerr << "Error: cannot read file " << input_filename << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -40,17 +40,8 @@ int main(int argc, char** argv)
CGAL::parameters::select_percentage(retain_percentage). CGAL::parameters::select_percentage(retain_percentage).
neighbor_radius (neighbor_radius)); neighbor_radius (neighbor_radius));
std::ofstream out(output_filename); if(!CGAL::write_points(output_filename, output, CGAL::parameters::stream_precision(17)))
out.precision(17);
if (!out || !CGAL::write_XYZ(
out, output))
{
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/IO/write_ply_points.h> #include <CGAL/IO/write_ply_points.h>
@ -21,6 +22,7 @@ typedef CGAL::Nth_of_tuple_property_map<2, PCI> Intensity_map;
// Define how a color should be stored // Define how a color should be stored
namespace CGAL { namespace CGAL {
template< class F > template< class F >
struct Output_rep< ::Color, F > { struct Output_rep< ::Color, F > {
const ::Color& c; const ::Color& c;
@ -36,8 +38,8 @@ namespace CGAL {
return out; return out;
} }
}; };
}
} // namespace CGAL
int main(int, char**) int main(int, char**)
{ {
@ -54,8 +56,7 @@ int main(int, char**)
std::ofstream f("out.ply", std::ios::binary); std::ofstream f("out.ply", std::ios::binary);
CGAL::set_binary_mode(f); // The PLY file will be written in the binary format CGAL::set_binary_mode(f); // The PLY file will be written in the binary format
CGAL::write_PLY_with_properties CGAL::write_PLY_with_properties(f, points,
(f, points,
CGAL::make_ply_point_writer (Point_map()), CGAL::make_ply_point_writer (Point_map()),
std::make_tuple(Color_map(), std::make_tuple(Color_map(),
CGAL::PLY_property<unsigned char>("red"), CGAL::PLY_property<unsigned char>("red"),

View File

@ -1,12 +1,3 @@
// STL includes.
#include <string>
#include <vector>
#include <utility>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
// CGAL includes. // CGAL includes.
#include <CGAL/array.h> #include <CGAL/array.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
@ -16,6 +7,15 @@
#include <CGAL/Shape_detection/Region_growing/Region_growing.h> #include <CGAL/Shape_detection/Region_growing/Region_growing.h>
#include <CGAL/Shape_detection/Region_growing/Region_growing_on_point_set.h> #include <CGAL/Shape_detection/Region_growing/Region_growing_on_point_set.h>
// STL includes.
#include <string>
#include <vector>
#include <utility>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
// Type declarations. // Type declarations.
using Kernel = CGAL::Simple_cartesian<double>; using Kernel = CGAL::Simple_cartesian<double>;

View File

@ -6,8 +6,7 @@
#include <CGAL/IO/OFF.h> #include <CGAL/IO/OFF.h>
#include <CGAL/IO/read_points.h> #include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_off_points.h> #include <CGAL/IO/write_points.h>
#include <CGAL/IO/write_xyz_points.h>
#include <CGAL/Iterator_range.h> #include <CGAL/Iterator_range.h>