mirror of https://github.com/CGAL/cgal
Add tests for deprecated functions of PSP
This commit is contained in:
parent
4e497f1c15
commit
2dc3f84478
|
|
@ -42,6 +42,16 @@ if ( CGAL_FOUND )
|
|||
create_single_source_cgal_program( "edge_aware_upsample_test.cpp" )
|
||||
create_single_source_cgal_program( "structuring_test.cpp" )
|
||||
|
||||
# Deprecated tests
|
||||
create_single_source_cgal_program( "deprecated_read_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_read_test_with_different_pmaps.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_analysis_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_remove_outliers_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_wlop_simplify_and_regularize_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_bilateral_smoothing_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_edge_aware_upsample_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_structuring_test.cpp" )
|
||||
|
||||
# Use Eigen or BLAS and LAPACK (optional)
|
||||
find_package(Eigen3 3.1.0) #(requires 3.1.0 or greater)
|
||||
if (NOT EIGEN3_FOUND)
|
||||
|
|
@ -63,6 +73,14 @@ if ( CGAL_FOUND )
|
|||
create_single_source_cgal_program( "vcm_all_test.cpp" )
|
||||
create_single_source_cgal_program( "jet_pointer_as_property_map.cpp" )
|
||||
|
||||
# Deprecated tests
|
||||
create_single_source_cgal_program( "deprecated_normal_estimation_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_hierarchy_simplification_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_smoothing_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_vcm_plane_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_vcm_all_test.cpp" )
|
||||
create_single_source_cgal_program( "deprecated_jet_pointer_as_property_map.cpp" )
|
||||
|
||||
else(EIGEN3_FOUND OR LAPACK_FOUND)
|
||||
|
||||
message(STATUS "NOTICE: This program requires either Eigen 3.1 (or greater) or LAPACK, and will not be compiled.")
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
data/*.xyz
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// analysis_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the analysis methods:
|
||||
// For each input point set, compute the average spacing.
|
||||
// Input format is .xyz.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// analysis_test points1.xyz points2.xyz...
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/compute_average_spacing.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <deque>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<float> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
|
||||
// Concurrency
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
typedef CGAL::Parallel_tag Concurrency_tag;
|
||||
#else
|
||||
typedef CGAL::Sequential_tag Concurrency_tag;
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Computes average spacing.
|
||||
void test_average_spacing(std::deque<Point>& points, // input point set
|
||||
unsigned int nb_neighbors) // number of neighbors
|
||||
{
|
||||
std::cerr << "Computes average spacing to k nearest neighbors (k="<< nb_neighbors << ")... ";
|
||||
CGAL::Timer task_timer; task_timer.start();
|
||||
|
||||
FT average_spacing = CGAL::compute_average_spacing<Concurrency_tag>(points.begin(), points.end(), nb_neighbors);
|
||||
std::cout << average_spacing << std::endl;
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "ok: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "Analysis test" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "For each input point set, compute the average spacing.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file format is .xyz.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Average Spacing options
|
||||
const unsigned int nb_neighbors = 6; // K-nearest neighbors = 1 ring (average spacing)
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
std::deque<Point> points;
|
||||
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If XYZ file format:
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
if(stream &&
|
||||
CGAL::read_xyz_points(stream, std::back_inserter(points)))
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Test
|
||||
//***************************************
|
||||
|
||||
test_average_spacing(points, nb_neighbors);
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/fin90_with_PCA_normals.xyz
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// bilateral_smoothing_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the smoothing methods:
|
||||
// For each input point set, smooth it.
|
||||
// Input format is .xyz.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// bilateral_smoothing_test points1.xyz points2.xyz...
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Real_timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/bilateral_smooth_point_set.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <deque>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
|
||||
// Point with normal vector stored in a std::pair.
|
||||
typedef std::pair<Point, Vector> PointVectorPair;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
template<typename Concurrency_tag>
|
||||
void test_bilateral_smoothing(std::deque<PointVectorPair>& points,// input point set
|
||||
unsigned int nb_neighbors, // number of neighbors
|
||||
double sharpness_sigma)
|
||||
{
|
||||
CGAL::Real_timer task_timer; task_timer.start();
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
CGAL::bilateral_smooth_point_set <Concurrency_tag>(
|
||||
points.begin(),
|
||||
points.end(),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>(),
|
||||
nb_neighbors,
|
||||
sharpness_sigma);
|
||||
}
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "ok: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "Bilateral smoothing test" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "For each input point set, smooth it.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file format is .xyz.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Smoothing options
|
||||
const unsigned int nb_neighbors = 50; // K-nearest neighbors
|
||||
const double sharpness_sigma = 25; // control sharpness
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
std::deque<PointVectorPair> points;
|
||||
std::cerr << "Opening " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If XYZ file format:
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
if(stream &&
|
||||
CGAL::read_xyz_points_and_normals(stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>()))
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Test
|
||||
//***************************************
|
||||
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
std::deque<PointVectorPair> points2(points);
|
||||
#endif // CGAL_LINKED_WITH_TBB
|
||||
|
||||
test_bilateral_smoothing<CGAL::Sequential_tag>(
|
||||
points, nb_neighbors, sharpness_sigma);
|
||||
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
test_bilateral_smoothing<CGAL::Parallel_tag>(
|
||||
points2, nb_neighbors, sharpness_sigma);
|
||||
#endif // CGAL_LINKED_WITH_TBB
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/before_upsample.xyz
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// edge_aware_upsample_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the edge aware up-sample test method:
|
||||
// Input format is .xyz.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// edge_aware_upsample_test points1.xyz points2.xyz...
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Real_timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/edge_aware_upsample_point_set.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<float> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
|
||||
// Point with normal vector stored in a std::pair.
|
||||
typedef std::pair<Point, Vector> PointVectorPair;
|
||||
|
||||
// Concurrency
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
typedef CGAL::Parallel_tag Concurrency_tag;
|
||||
#else
|
||||
typedef CGAL::Sequential_tag Concurrency_tag;
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void test_edge_aware_upsample(std::vector<PointVectorPair>& points, // input point set
|
||||
double sharpness_sigma, //control sharpness
|
||||
double edge_sensitivity,// more points will up-sample on edge
|
||||
double neighbor_radius, // initial neighbors size.
|
||||
unsigned int times_of_output_points)
|
||||
|
||||
{
|
||||
CGAL::Real_timer task_timer; task_timer.start();
|
||||
std::cerr << "Running edge aware up-sample, (sharpness_sigma: "
|
||||
<< sharpness_sigma << "%, number_of_output_points="
|
||||
<< points.size() * times_of_output_points << ")...\n";
|
||||
|
||||
//Run algorithm
|
||||
CGAL::edge_aware_upsample_point_set<Concurrency_tag>(
|
||||
points.begin(),
|
||||
points.end(),
|
||||
std::back_inserter(points),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>(),
|
||||
sharpness_sigma,
|
||||
edge_sensitivity,
|
||||
neighbor_radius,
|
||||
points.size() * times_of_output_points);
|
||||
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "ok: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "Edge aware up-sample" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "Upsample each input point set.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file format is .xyz.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Algorithm parameters
|
||||
const double sharpness_sigma = 25; //control sharpness of the result.
|
||||
const double edge_sensitivity = 0; // more points will up-sample on edge.
|
||||
const double neighbor_radius = 0.2; // initial neighbors size.
|
||||
const unsigned int times_of_output_points = 4;
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
std::vector<PointVectorPair> points;
|
||||
std::cerr << "Opening " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If XYZ file format:
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
if(stream &&
|
||||
CGAL::read_xyz_points_and_normals
|
||||
(stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>()))
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Test
|
||||
//***************************************
|
||||
|
||||
test_edge_aware_upsample(points,
|
||||
sharpness_sigma,
|
||||
edge_sensitivity,
|
||||
neighbor_radius,
|
||||
times_of_output_points);
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/hierarchy_simplify_point_set.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
// types
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::FT FT;
|
||||
|
||||
void test (std::vector<Point>& input,
|
||||
std::ptrdiff_t result0 = 1, int result1 = 1, int result2 = 1, int result3 = 1, int result4 = 1)
|
||||
{
|
||||
std::vector<Point>::iterator it =
|
||||
CGAL::hierarchy_simplify_point_set (input.begin (), input.end (), 1);
|
||||
if (result0 > 0 && std::distance (input.begin (), it) != result0)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
it = CGAL::hierarchy_simplify_point_set (input.begin (), input.end ());
|
||||
if (result1 > 0 && std::distance (input.begin (), it) != result1)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
it = CGAL::hierarchy_simplify_point_set (input.begin (), input.end (), 100);
|
||||
if (result2 > 0 && std::distance (input.begin (), it) != result2)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
|
||||
it = CGAL::hierarchy_simplify_point_set (input.begin (), input.end (), 1000, 0.1);
|
||||
if (result3 > 0 && std::distance (input.begin (), it) != result3)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
|
||||
it = CGAL::hierarchy_simplify_point_set (input.begin (), input.end (),
|
||||
CGAL::Identity_property_map<Point>(),
|
||||
(std::numeric_limits<unsigned int>::max)(),
|
||||
0.0001);
|
||||
if (result4 > 0 && std::distance (input.begin (), it) != result4)
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
input.clear ();
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
std::vector<Point> input;
|
||||
|
||||
// Test 1 point
|
||||
input.push_back (Point (0., 0., 0.));
|
||||
test (input);
|
||||
|
||||
// Test twice the same point
|
||||
input.push_back (Point (0., 0., 0.));
|
||||
input.push_back (Point (0., 0., 0.));
|
||||
test (input);
|
||||
|
||||
// Test 2 points
|
||||
input.push_back (Point (0., 0., 0.));
|
||||
input.push_back (Point (1., 0., 0.));
|
||||
test (input, 2);
|
||||
|
||||
// Test line
|
||||
for (std::size_t i = 0; i < 1000; ++ i)
|
||||
input.push_back (Point (0., 0., (double)i));
|
||||
test (input, input.size (), 128, 16, 1, 1);
|
||||
|
||||
// Test plane
|
||||
for (std::size_t i = 0; i < 128; ++ i)
|
||||
for (std::size_t j = 0; j < 128; ++ j)
|
||||
input.push_back (Point (0., (double)j, (double)i));
|
||||
test (input, input.size (), 2048, 256, 32, 1);
|
||||
|
||||
// Test random
|
||||
for (std::size_t i = 0; i < 10000; ++ i)
|
||||
input.push_back (Point (rand() / (FT)RAND_MAX,
|
||||
rand() / (FT)RAND_MAX,
|
||||
rand() / (FT)RAND_MAX));
|
||||
test (input, input.size (), -1, -1, -1, -1);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/jet_estimate_normals.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Vector_3 Vector_3;
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<Point_3> points;
|
||||
std::vector<size_t> indices(100);
|
||||
|
||||
for(int i=0; i < 100; i++){
|
||||
indices[i] = i;
|
||||
}
|
||||
std::vector<Vector_3> normals(100);
|
||||
|
||||
|
||||
for(int i=0; i <10; i++){
|
||||
for(int j=0; j <10; j++){
|
||||
points.push_back(Point_3(i,j,0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CGAL::jet_estimate_normals<CGAL::Sequential_tag>(indices.begin(), indices.end(),
|
||||
CGAL::make_property_map(points),
|
||||
CGAL::make_property_map(normals),
|
||||
12);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/sphere926.pwn data/sphere_1k.xyz
|
||||
|
|
@ -0,0 +1,407 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// normal_estimation_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the normal estimation methods:
|
||||
// For each input point set, compute and orient its normals.
|
||||
// If an input mesh has normals, print the normal deviation.
|
||||
// Input file formats are .off, .xyz and .pwn.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// normal_estimation_test points1.xyz points2.xyz...
|
||||
|
||||
// With iterator debugging this testsuite takes to long and the process gets killed
|
||||
//#define _HAS_ITERATOR_DEBUGGING 0
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/pca_estimate_normals.h>
|
||||
#include <CGAL/jet_estimate_normals.h>
|
||||
#include <CGAL/mst_orient_normals.h>
|
||||
#include <CGAL/Point_with_normal_3.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/IO/read_off_points.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal; // position + normal vector
|
||||
typedef std::vector<Point_with_normal> PointList;
|
||||
|
||||
// Concurrency
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
typedef CGAL::Parallel_tag Concurrency_tag;
|
||||
#else
|
||||
typedef CGAL::Sequential_tag Concurrency_tag;
|
||||
#endif
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Check the accuracy of normals direction estimation.
|
||||
// If original normals are available, compare with them and count normals with large deviation.
|
||||
// @return true on success.
|
||||
bool verify_normal_direction(const PointList& points, // input points + computed normals
|
||||
const std::vector<Vector>& original_normals) // may be empty
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
bool points_have_original_normals = ! original_normals.empty();
|
||||
if (points_have_original_normals)
|
||||
{
|
||||
assert(points.size() == original_normals.size());
|
||||
|
||||
std::cerr << "Compare with original normals:" << std::endl;
|
||||
|
||||
double min_normal_deviation = DBL_MAX; // deviation / original normal
|
||||
double max_normal_deviation = DBL_MIN;
|
||||
double avg_normal_deviation = 0;
|
||||
int invalid_normals = 0; // #normals with large deviation
|
||||
PointList::const_iterator p;
|
||||
std::vector<Vector>::const_iterator n;
|
||||
for (p = points.begin(), n = original_normals.begin(); p != points.end(); p++, n++)
|
||||
{
|
||||
// Computes normal deviation.
|
||||
Vector v1 = *n; // original normal
|
||||
double norm1 = std::sqrt( v1*v1 );
|
||||
assert(norm1 != 0.0);
|
||||
Vector v2 = p->normal(); // computed normal
|
||||
double norm2 = std::sqrt( v2*v2 );
|
||||
assert(norm2 != 0.0);
|
||||
double cos_normal_deviation = (v1*v2)/(norm1*norm2);
|
||||
if (cos_normal_deviation < 0)
|
||||
{
|
||||
cos_normal_deviation = -cos_normal_deviation;
|
||||
}
|
||||
double normal_deviation = std::acos(cos_normal_deviation);
|
||||
|
||||
// statistics about normals deviation
|
||||
min_normal_deviation = (std::min)(min_normal_deviation, normal_deviation);
|
||||
max_normal_deviation = (std::max)(max_normal_deviation, normal_deviation);
|
||||
avg_normal_deviation += normal_deviation;
|
||||
|
||||
// count normal if large deviation
|
||||
bool valid = (normal_deviation <= CGAL_PI/3.); // valid if deviation <= 60 degrees
|
||||
if ( ! valid )
|
||||
{
|
||||
invalid_normals++;
|
||||
}
|
||||
}
|
||||
avg_normal_deviation /= double(points.size());
|
||||
|
||||
std::cerr << " Min normal deviation=" << min_normal_deviation*180.0/CGAL_PI << " degrees\n";
|
||||
std::cerr << " Max normal deviation=" << max_normal_deviation*180.0/CGAL_PI << " degrees\n";
|
||||
std::cerr << " Avg normal deviation=" << avg_normal_deviation*180.0/CGAL_PI << " degrees\n";
|
||||
if (invalid_normals > 0)
|
||||
{
|
||||
std::cerr << " Error: " << invalid_normals << " normals have a deviation > 60 degrees\n";
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Computes normals direction by Principal Component Analysis
|
||||
// @return true on success.
|
||||
bool run_pca_estimate_normals(PointList& points, // input points + output normals
|
||||
unsigned int nb_neighbors_pca_normals, // number of neighbors
|
||||
const std::vector<Vector>& original_normals) // may be empty
|
||||
{
|
||||
CGAL::Timer task_timer; task_timer.start();
|
||||
std::cerr << "Estimates Normals Direction by PCA (k="
|
||||
<< nb_neighbors_pca_normals << ")...\n";
|
||||
|
||||
CGAL::pca_estimate_normals<Concurrency_tag>(points.begin(), points.end(),
|
||||
CGAL::make_normal_of_point_with_normal_map(PointList::value_type()),
|
||||
nb_neighbors_pca_normals);
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "done: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
|
||||
// Check the accuracy of normals direction estimation.
|
||||
// If original normals are available, compare with them.
|
||||
return verify_normal_direction(points, original_normals);
|
||||
}
|
||||
|
||||
// Computes normals direction by Jet Fitting
|
||||
// @return true on success.
|
||||
bool run_jet_estimate_normals(PointList& points, // input points + output normals
|
||||
unsigned int nb_neighbors_jet_fitting_normals, // number of neighbors
|
||||
const std::vector<Vector>& original_normals) // may be empty
|
||||
{
|
||||
CGAL::Timer task_timer; task_timer.start();
|
||||
std::cerr << "Estimates Normals Direction by Jet Fitting (k="
|
||||
<< nb_neighbors_jet_fitting_normals << ")...\n";
|
||||
|
||||
CGAL::jet_estimate_normals<Concurrency_tag>(points.begin(), points.end(),
|
||||
CGAL::make_normal_of_point_with_normal_map(PointList::value_type()),
|
||||
nb_neighbors_jet_fitting_normals);
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "done: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
|
||||
// Check the accuracy of normals direction estimation.
|
||||
// If original normals are available, compare with them.
|
||||
return verify_normal_direction(points, original_normals);
|
||||
}
|
||||
|
||||
// Check the accuracy of normal orientation.
|
||||
// Count non-oriented normals.
|
||||
// If original normals are available, compare with them and count flipped normals.
|
||||
bool verify_normal_orientation(const PointList& points, // input points + computed normals
|
||||
PointList::const_iterator unoriented_points_begin, // first pt w/ unoriented normal
|
||||
const std::vector<Vector>& original_normals) // may be empty
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
// Count non-oriented normals
|
||||
int unoriented_normals = 0;
|
||||
for (PointList::const_iterator p = unoriented_points_begin ; p != points.end(); p++)
|
||||
{
|
||||
unoriented_normals++;
|
||||
}
|
||||
if (unoriented_normals > 0)
|
||||
{
|
||||
std::cerr << "Error: " << unoriented_normals << " normals are unoriented\n";
|
||||
success = false;
|
||||
}
|
||||
|
||||
// Compare oriented normals with original ones and count flipped normals
|
||||
bool points_have_original_normals = ! original_normals.empty();
|
||||
if (points_have_original_normals)
|
||||
{
|
||||
assert(points.size() == original_normals.size());
|
||||
|
||||
std::cerr << "Compare with original normals:" << std::endl;
|
||||
|
||||
int flipped_normals = 0; // #normals with wrong orientation
|
||||
PointList::const_iterator p;
|
||||
std::vector<Vector>::const_iterator n;
|
||||
for (p = points.begin(), n = original_normals.begin(); p != unoriented_points_begin; p++, n++)
|
||||
{
|
||||
Vector v1 = *n; // original normal
|
||||
double norm1 = std::sqrt( v1*v1 );
|
||||
assert(norm1 != 0.0);
|
||||
Vector v2 = p->normal(); // computed normal
|
||||
double norm2 = std::sqrt( v2*v2 );
|
||||
assert(norm2 != 0.0);
|
||||
double cos_normal_deviation = (v1*v2)/(norm1*norm2);
|
||||
if (cos_normal_deviation < 0) // if flipped
|
||||
{
|
||||
flipped_normals++;
|
||||
}
|
||||
}
|
||||
|
||||
if (flipped_normals == 0)
|
||||
std::cerr << " ok\n";
|
||||
else
|
||||
std::cerr << " Error: " << flipped_normals << " normal(s) are flipped\n";
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Hoppe92 normal orientation using a Minimum Spanning Tree.
|
||||
// @return true on success.
|
||||
bool run_mst_orient_normals(PointList& points, // input points + input/output normals
|
||||
unsigned int nb_neighbors_mst, // number of neighbors
|
||||
const std::vector<Vector>& original_normals) // may be empty
|
||||
{
|
||||
#if (BOOST_VERSION / 100) == 1054
|
||||
std::cerr <<
|
||||
"In run_mst_orient_normals():\n"
|
||||
"NOTICE: This function is incompatible with Boost 1.54, "
|
||||
"and will not be tested. See the following bug:\n"
|
||||
" https://svn.boost.org/trac/boost/ticket/9012\n";
|
||||
return true;
|
||||
#endif // Boost version is 1.54
|
||||
|
||||
std::cerr << "Orients Normals with a Minimum Spanning Tree (k="<< nb_neighbors_mst << ")...\n";
|
||||
CGAL::Timer task_timer; task_timer.start();
|
||||
|
||||
PointList::iterator unoriented_points_begin =
|
||||
CGAL::mst_orient_normals(points.begin(), points.end(),
|
||||
CGAL::make_normal_of_point_with_normal_map(PointList::value_type()),
|
||||
nb_neighbors_mst);
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "done: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
|
||||
// Note: we do *not* delete points with unoriented normals in this test.
|
||||
// Instead, we check the accuracy of normal orientation and,
|
||||
// if original normals are available, compare with them.
|
||||
return verify_normal_orientation(points, unoriented_points_begin, original_normals);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "Normal estimation test" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "For each input point set, compute and orient its normals.\n";
|
||||
std::cerr << "If an input mesh has normals, print the normals deviation.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file formats are .off, .xyz and .pwn.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Normals Computing options
|
||||
unsigned int nb_neighbors_pca_normals = 18; // K-nearest neighbors = 3 rings (estimate normals by PCA)
|
||||
unsigned int nb_neighbors_jet_fitting_normals = 18; // K-nearest neighbors (estimate normals by Jet Fitting)
|
||||
unsigned int nb_neighbors_mst = 18; // K-nearest neighbors (orient normals by MST)
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
PointList points;
|
||||
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If OFF file format
|
||||
bool success = false;
|
||||
std::string extension = input_filename.substr(input_filename.find_last_of('.'));
|
||||
if (extension == ".off" || extension == ".OFF")
|
||||
{
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
success = stream &&
|
||||
CGAL::read_off_points_and_normals(stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::make_normal_of_point_with_normal_map(PointList::value_type())
|
||||
);
|
||||
}
|
||||
// If XYZ file format
|
||||
else if (extension == ".xyz" || extension == ".XYZ" ||
|
||||
extension == ".pwn" || extension == ".PWN")
|
||||
{
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
success = stream &&
|
||||
CGAL::read_xyz_points_and_normals(stream,
|
||||
std::back_inserter(points),
|
||||
CGAL::make_normal_of_point_with_normal_map(PointList::value_type())
|
||||
);
|
||||
}
|
||||
if (success)
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Check requirements
|
||||
//***************************************
|
||||
|
||||
if (points.size() == 0)
|
||||
{
|
||||
std::cerr << "Error: empty file" << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Copy original normals
|
||||
//***************************************
|
||||
|
||||
std::vector<Vector> original_normals;
|
||||
bool points_have_original_normals = (points.begin()->normal() != CGAL::NULL_VECTOR);
|
||||
if ( points_have_original_normals )
|
||||
{
|
||||
for (PointList::iterator p = points.begin() ; p != points.end(); p++)
|
||||
original_normals.push_back(p->normal());
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Computes normals (PCA + MST)
|
||||
//***************************************
|
||||
|
||||
// Estimates normals direction.
|
||||
success = run_pca_estimate_normals(points, nb_neighbors_pca_normals, original_normals);
|
||||
if ( ! success )
|
||||
accumulated_fatal_err = EXIT_FAILURE; // set error and continue
|
||||
|
||||
// Orients normals.
|
||||
success = run_mst_orient_normals(points, nb_neighbors_mst, original_normals);
|
||||
if ( ! success )
|
||||
accumulated_fatal_err = EXIT_FAILURE; // set error and continue
|
||||
|
||||
//***************************************
|
||||
// Computes normals (jet fitting + MST)
|
||||
//***************************************
|
||||
|
||||
// Estimates normals direction
|
||||
success = run_jet_estimate_normals(points, nb_neighbors_jet_fitting_normals, original_normals);
|
||||
if ( ! success )
|
||||
accumulated_fatal_err = EXIT_FAILURE; // set error and continue
|
||||
|
||||
// Orients normals
|
||||
success = run_mst_orient_normals(points, nb_neighbors_mst, original_normals);
|
||||
if ( ! success )
|
||||
accumulated_fatal_err = EXIT_FAILURE; // set error and continue
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/IO/read_off_points.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <CGAL/config.h>
|
||||
#ifdef CGAL_CXX11
|
||||
#include <CGAL/IO/read_ply_points.h>
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Vector_3 Vector_3;
|
||||
typedef std::pair<Point_3, Vector_3> PointVectorPair;
|
||||
|
||||
bool read(std::string s)
|
||||
{
|
||||
std::ifstream fs(s.c_str());
|
||||
std::vector<PointVectorPair> pv_pairs;
|
||||
return CGAL::read_xyz_points_and_normals(fs,
|
||||
back_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool read(std::string s,
|
||||
std::vector<PointVectorPair>& pv_pairs)
|
||||
{
|
||||
std::ifstream fs(s.c_str());
|
||||
|
||||
return CGAL::read_xyz_points_and_normals(fs,
|
||||
back_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>());
|
||||
}
|
||||
|
||||
bool read_off(std::string s,
|
||||
std::vector<PointVectorPair>& pv_pairs)
|
||||
{
|
||||
std::ifstream fs(s.c_str());
|
||||
|
||||
return CGAL::read_off_points_and_normals(fs,
|
||||
back_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>());
|
||||
}
|
||||
|
||||
#ifdef CGAL_CXX11
|
||||
bool read_ply (std::string s,
|
||||
std::vector<PointVectorPair>& pv_pairs)
|
||||
{
|
||||
std::ifstream fs(s.c_str());
|
||||
|
||||
return CGAL::read_ply_points_and_normals (fs,
|
||||
back_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>());
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cerr << "### There should be three errors following this line...\n";
|
||||
assert(! read("data/read_test/bug_1.xyz"));
|
||||
assert(! read("data/read_test/bug_2.xyz"));
|
||||
assert(! read("data/read_test/bug_3.xyz"));
|
||||
std::cerr << "### ... Done. Now, there should not be any error.\n";
|
||||
|
||||
assert(read("data/read_test/ok_1.xyz"));
|
||||
assert(read("data/read_test/ok_2.xyz"));
|
||||
assert(read("data/read_test/ok_3.xyz"));
|
||||
|
||||
std::vector<PointVectorPair> pv_pairs;
|
||||
|
||||
read("data/read_test/ok_2.xyz", pv_pairs);
|
||||
assert(pv_pairs.size() == 4);
|
||||
assert(pv_pairs[0] == std::make_pair(Point_3(2,3,4), Vector_3(4,4,2)));
|
||||
assert(pv_pairs[1] == std::make_pair(Point_3(3,4,6), Vector_3(0,0,0)));
|
||||
assert(pv_pairs[2] == std::make_pair(Point_3(3,6,7), Vector_3(3,5,6)));
|
||||
assert(pv_pairs[3] == std::make_pair(Point_3(1,3,4), Vector_3(4,6,8)));
|
||||
|
||||
pv_pairs.clear();
|
||||
|
||||
assert(read_off("data/read_test/ok_1.off", pv_pairs));
|
||||
assert(pv_pairs.size() == 4);
|
||||
assert(pv_pairs[0] == std::make_pair(Point_3(3,2,0), Vector_3(1,2,3)));
|
||||
assert(pv_pairs[1] == std::make_pair(Point_3(1,2,3), Vector_3(0,0,0)));
|
||||
assert(pv_pairs[2] == std::make_pair(Point_3(4,5,6), Vector_3(0,0,0)));
|
||||
assert(pv_pairs[3] == std::make_pair(Point_3(7,8,9), Vector_3(0,0,0)));
|
||||
|
||||
#ifdef CGAL_CXX11
|
||||
pv_pairs.clear ();
|
||||
assert(read_ply("data/read_test/simple.ply", pv_pairs));
|
||||
assert(pv_pairs[0] == std::make_pair(Point_3(1,1,1), Vector_3(2,2,2)));
|
||||
assert(pv_pairs[1] == std::make_pair(Point_3(3,3,3), Vector_3(4,4,4)));
|
||||
assert(pv_pairs[2] == std::make_pair(Point_3(5,5,5), Vector_3(6,6,6)));
|
||||
|
||||
pv_pairs.clear ();
|
||||
assert(read_ply("data/read_test/simple_ascii.ply", pv_pairs));
|
||||
assert(pv_pairs[0] == std::make_pair(Point_3(1,1,1), Vector_3(2,2,2)));
|
||||
assert(pv_pairs[1] == std::make_pair(Point_3(3,3,3), Vector_3(4,4,4)));
|
||||
assert(pv_pairs[2] == std::make_pair(Point_3(5,5,5), Vector_3(6,6,6)));
|
||||
|
||||
pv_pairs.clear ();
|
||||
assert(read_ply("data/read_test/simple_with_flag.ply", pv_pairs));
|
||||
assert(pv_pairs[0] == std::make_pair(Point_3(1,1,1), Vector_3(2,2,2)));
|
||||
assert(pv_pairs[1] == std::make_pair(Point_3(3,3,3), Vector_3(4,4,4)));
|
||||
assert(pv_pairs[2] == std::make_pair(Point_3(5,5,5), Vector_3(6,6,6)));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,340 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/property_map.h>
|
||||
#include <CGAL/IO/read_off_points.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
#include <CGAL/property_map.h>
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point_3;
|
||||
typedef Kernel::Vector_3 Vector_3;
|
||||
typedef std::pair<Point_3, Vector_3> PointVectorPair;
|
||||
|
||||
// this is going to be custom OutputIterator value_type
|
||||
struct dummy_counter {
|
||||
static std::size_t counter;
|
||||
|
||||
dummy_counter() { ++counter; }
|
||||
operator std::size_t() { return counter-1; }
|
||||
};
|
||||
std::size_t dummy_counter::counter = 0;
|
||||
|
||||
bool check_points_and_vectors(
|
||||
const boost::vector_property_map<Point_3>& points,
|
||||
const boost::vector_property_map<Vector_3>& normals,
|
||||
const std::vector<PointVectorPair>& pv_pairs,
|
||||
const std::vector<std::size_t>& indices)
|
||||
{
|
||||
if(pv_pairs.size() != indices.size()) {
|
||||
std::cerr << "Error: inconsistency between point / normal size." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < pv_pairs.size(); ++i ) {
|
||||
if(pv_pairs[i].first != points[i]) {
|
||||
std::cerr << "Error: points are not equal." << std::endl;
|
||||
return false;
|
||||
}
|
||||
if(pv_pairs[i].second != normals[i]) {
|
||||
std::cerr << "Error: normals are not equal." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool check_points(
|
||||
const boost::vector_property_map<Point_3>& points_1,
|
||||
const std::vector<Point_3>& points_2,
|
||||
const std::vector<std::size_t>& indices)
|
||||
{
|
||||
if(points_2.size() != indices.size()) {
|
||||
std::cerr << "Error: inconsistency between point / normal size." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < points_2.size(); ++i ) {
|
||||
if(points_2[i] != points_1[i]) {
|
||||
std::cerr << "Error: points are not equal." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_no_deduction_points_and_normals_xyz(const char* file_name)
|
||||
{
|
||||
boost::vector_property_map<Point_3> points;
|
||||
boost::vector_property_map<Vector_3> normals;
|
||||
std::vector<std::size_t> indices;
|
||||
|
||||
std::vector<PointVectorPair> pv_pairs;
|
||||
|
||||
// read with custom output iterator type
|
||||
dummy_counter::counter = 0;
|
||||
std::ifstream input(file_name);
|
||||
CGAL::read_xyz_points_and_normals<dummy_counter>(
|
||||
input, back_inserter(indices), points, normals, Kernel());
|
||||
|
||||
// read with ordinary pmaps
|
||||
input.clear();
|
||||
input.close();
|
||||
input.open(file_name);
|
||||
CGAL::read_xyz_points_and_normals(
|
||||
input, back_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>(),
|
||||
Kernel());
|
||||
|
||||
return check_points_and_vectors(points, normals, pv_pairs, indices);
|
||||
}
|
||||
|
||||
bool test_no_deduction_points_and_normals_off(const char* file_name)
|
||||
{
|
||||
boost::vector_property_map<Point_3> points;
|
||||
boost::vector_property_map<Vector_3> normals;
|
||||
std::vector<std::size_t> indices;
|
||||
|
||||
std::vector<PointVectorPair> pv_pairs;
|
||||
|
||||
// read with custom output iterator type
|
||||
dummy_counter::counter = 0;
|
||||
std::ifstream input(file_name);
|
||||
CGAL::read_off_points_and_normals<dummy_counter>(
|
||||
input, back_inserter(indices), points, normals, Kernel());
|
||||
|
||||
// read with ordinary pmaps
|
||||
input.clear();
|
||||
input.close();
|
||||
input.open(file_name);
|
||||
CGAL::read_off_points_and_normals(
|
||||
input, back_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>(),
|
||||
Kernel());
|
||||
|
||||
return check_points_and_vectors(points, normals, pv_pairs, indices);
|
||||
}
|
||||
|
||||
bool test_no_deduction_points_xyz(const char* file_name)
|
||||
{
|
||||
boost::vector_property_map<Point_3> points_1; \
|
||||
std::vector<std::size_t> indices;
|
||||
|
||||
std::vector<Point_3> points_2;
|
||||
|
||||
// read with custom output iterator type
|
||||
dummy_counter::counter = 0;
|
||||
std::ifstream input(file_name);
|
||||
CGAL::read_xyz_points<dummy_counter>(
|
||||
input, back_inserter(indices), points_1, Kernel());
|
||||
|
||||
// read with ordinary pmaps
|
||||
input.clear();
|
||||
input.close();
|
||||
input.open(file_name);
|
||||
CGAL::read_xyz_points(
|
||||
input, back_inserter(points_2),
|
||||
CGAL::Identity_property_map<Point_3>(),
|
||||
Kernel());
|
||||
|
||||
return check_points(points_1, points_2, indices);
|
||||
}
|
||||
|
||||
bool test_no_deduction_points_off(const char* file_name)
|
||||
{
|
||||
boost::vector_property_map<Point_3> points_1;
|
||||
std::vector<std::size_t> indices;
|
||||
|
||||
std::vector<Point_3> points_2;
|
||||
|
||||
// read with custom output iterator type
|
||||
dummy_counter::counter = 0;
|
||||
std::ifstream input(file_name);
|
||||
CGAL::read_off_points<dummy_counter>(
|
||||
input, back_inserter(indices), points_1, Kernel());
|
||||
|
||||
// read with ordinary pmaps
|
||||
input.clear();
|
||||
input.close();
|
||||
input.open(file_name);
|
||||
CGAL::read_off_points(
|
||||
input, back_inserter(points_2),
|
||||
CGAL::Identity_property_map<Point_3>(),
|
||||
Kernel());
|
||||
|
||||
return check_points(points_1, points_2, indices);
|
||||
}
|
||||
|
||||
void compile_test() {
|
||||
std::deque<Point_3> points;
|
||||
std::deque<Vector_3> normals;
|
||||
std::deque<PointVectorPair> pv_pairs;
|
||||
std::ifstream input;
|
||||
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points(
|
||||
input,
|
||||
std::front_inserter(points));
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
CGAL::Identity_property_map<Point_3>());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
CGAL::Identity_property_map<Point_3>(),
|
||||
Kernel());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
// this will span all OutputIteratorValueType versions
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points<Point_3>(
|
||||
input,
|
||||
std::front_inserter(points));
|
||||
input.clear();
|
||||
input.close();
|
||||
//-----------------------------------------------------------------------
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points(
|
||||
input,
|
||||
std::front_inserter(points));
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
CGAL::Identity_property_map<Point_3>());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
CGAL::Identity_property_map<Point_3>(),
|
||||
Kernel());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
// this will span all OutputIteratorValueType versions
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points<Point_3>(
|
||||
input,
|
||||
std::front_inserter(points));
|
||||
input.clear();
|
||||
input.close();
|
||||
//-----------------------------------------------------------------------
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points_and_normals(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
boost::dummy_property_map());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points_and_normals(
|
||||
input,
|
||||
std::front_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points_and_normals(
|
||||
input,
|
||||
std::front_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>(),
|
||||
Kernel());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.xyz");
|
||||
CGAL::read_xyz_points_and_normals<Point_3>(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
boost::dummy_property_map());
|
||||
input.clear();
|
||||
input.close();
|
||||
//-----------------------------------------------------------------------
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points_and_normals(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
boost::dummy_property_map());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points_and_normals(
|
||||
input,
|
||||
std::front_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points_and_normals(
|
||||
input,
|
||||
std::front_inserter(pv_pairs),
|
||||
CGAL::First_of_pair_property_map<PointVectorPair>(),
|
||||
CGAL::Second_of_pair_property_map<PointVectorPair>(),
|
||||
Kernel());
|
||||
input.clear();
|
||||
input.close();
|
||||
|
||||
input.open("data/read_test/simple.off");
|
||||
CGAL::read_off_points_and_normals<Point_3>(
|
||||
input,
|
||||
std::front_inserter(points),
|
||||
boost::dummy_property_map());
|
||||
input.clear();
|
||||
input.close();
|
||||
}
|
||||
|
||||
int main() {
|
||||
if(!test_no_deduction_points_and_normals_xyz("data/read_test/simple.xyz")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cerr << "test_no_deduction_points_and_normals_xyz OK." << std::endl;
|
||||
|
||||
if(!test_no_deduction_points_and_normals_off("data/read_test/simple.off")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cerr << "test_no_deduction_points_and_normals_off OK." << std::endl;
|
||||
|
||||
if(!test_no_deduction_points_xyz("data/read_test/simple.xyz")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cerr << "test_no_deduction_points_xyz OK." << std::endl;
|
||||
|
||||
if(!test_no_deduction_points_off("data/read_test/simple.off")) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cerr << "test_no_deduction_points_off OK." << std::endl;
|
||||
|
||||
compile_test();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/*.xyz
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// remove_outliers_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the outlier removal methods:
|
||||
// For each input point set, remove outliers.
|
||||
// Input format is .xyz.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// remove_outliers_test points1.xyz points2.xyz...
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/remove_outliers.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<float> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Removes outliers
|
||||
void test_avg_knn_sq_distance(std::deque<Point>& points, // input point set
|
||||
unsigned int nb_neighbors_remove_outliers, // K-nearest neighbors
|
||||
double removed_percentage) // percentage of points to remove
|
||||
{
|
||||
CGAL::Timer task_timer; task_timer.start();
|
||||
std::cerr << "Removes outliers wrt average squared distance to k nearest neighbors (remove "
|
||||
<< removed_percentage << "%, k="
|
||||
<< nb_neighbors_remove_outliers << ")...\n";
|
||||
|
||||
// Removes outliers using erase-remove idiom
|
||||
points.erase(CGAL::remove_outliers(points.begin(), points.end(),
|
||||
nb_neighbors_remove_outliers, removed_percentage),
|
||||
points.end());
|
||||
|
||||
// Optional: after erase(), use Scott Meyer's "swap trick" to trim excess capacity
|
||||
std::deque<Point>(points).swap(points);
|
||||
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "ok: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "Outlier removal test" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "For each input point set, remove outliers.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file format is .xyz.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Outlier Removal options
|
||||
const double removed_percentage = 5.0 /* % */; // percentage of outliers to remove
|
||||
const unsigned int nb_neighbors_remove_outliers = 24; // K-nearest neighbors
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
std::deque<Point> points;
|
||||
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If XYZ file format:
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
if(stream &&
|
||||
CGAL::read_xyz_points(stream, std::back_inserter(points)))
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Test
|
||||
//***************************************
|
||||
|
||||
test_avg_knn_sq_distance(points, nb_neighbors_remove_outliers, removed_percentage);
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/*.xyz
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// smoothing_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the smoothing methods:
|
||||
// For each input point set, smooth it.
|
||||
// Input format is .xyz.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// smoothing_test points1.xyz points2.xyz...
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/jet_smooth_point_set.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
|
||||
// Concurrency
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
typedef CGAL::Parallel_tag Concurrency_tag;
|
||||
#else
|
||||
typedef CGAL::Sequential_tag Concurrency_tag;
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void test_smooth_jet_fitting(std::deque<Point>& points,// input point set
|
||||
unsigned int nb_neighbors_smooth_jet_fitting) // number of neighbors
|
||||
{
|
||||
CGAL::Timer task_timer; task_timer.start();
|
||||
std::cerr << "Smoothes Point Set (k=" << nb_neighbors_smooth_jet_fitting << ")...\n";
|
||||
|
||||
CGAL::jet_smooth_point_set<Concurrency_tag>(points.begin(), points.end(),
|
||||
nb_neighbors_smooth_jet_fitting);
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "ok: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "Smoothing test" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "For each input point set, smooth it.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file format is .xyz.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Smoothing options
|
||||
const unsigned int nb_neighbors_smooth_jet_fitting = 24; // K-nearest neighbors (smooth points by Jet Fitting)
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
std::deque<Point> points;
|
||||
std::cerr << "Open " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If XYZ file format:
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
if(stream &&
|
||||
CGAL::read_xyz_points(stream, std::back_inserter(points)))
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Test
|
||||
//***************************************
|
||||
|
||||
test_smooth_jet_fitting(points, nb_neighbors_smooth_jet_fitting);
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Point_with_normal_3.h>
|
||||
#include <CGAL/property_map.h>
|
||||
|
||||
#include <CGAL/Shape_detection_3.h>
|
||||
#include <CGAL/structure_point_set.h>
|
||||
|
||||
#include <CGAL/Random.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
typedef Kernel::Plane_3 Plane;
|
||||
typedef std::pair<Point, Vector> Point_with_normal;
|
||||
typedef std::vector<Point_with_normal> Pwn_vector;
|
||||
typedef CGAL::First_of_pair_property_map<Point_with_normal> Point_map;
|
||||
typedef CGAL::Second_of_pair_property_map<Point_with_normal> Normal_map;
|
||||
|
||||
typedef CGAL::Shape_detection_3::Shape_detection_traits
|
||||
<Kernel, Pwn_vector, Point_map, Normal_map> Traits;
|
||||
typedef CGAL::Shape_detection_3::Efficient_RANSAC<Traits> Efficient_ransac;
|
||||
|
||||
typedef CGAL::Point_set_with_structure<Kernel> Points_with_structure;
|
||||
|
||||
template <typename OutputIterator>
|
||||
void generate_random_points (const Point& origin, const Vector& base1, const Vector& base2,
|
||||
std::size_t nb_pts, OutputIterator output)
|
||||
{
|
||||
Vector normal = CGAL::cross_product (base1, base2);
|
||||
normal = normal / std::sqrt (normal * normal);
|
||||
|
||||
for (std::size_t i = 0; i < nb_pts; ++ i)
|
||||
{
|
||||
Point point = origin
|
||||
+ CGAL::get_default_random().get_double() * base1
|
||||
+ CGAL::get_default_random().get_double() * base2;
|
||||
|
||||
*(output ++) = std::make_pair (point, normal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Vector vx (1., 0., 0.),
|
||||
vy (0., 1., 0.),
|
||||
vz (0., 0., 1.);
|
||||
|
||||
Efficient_ransac ransac;
|
||||
ransac.add_shape_factory<CGAL::Shape_detection_3::Plane<Traits> >();
|
||||
|
||||
const std::size_t nb_pts = 1000;
|
||||
|
||||
Efficient_ransac::Parameters op;
|
||||
op.probability = 0.05;
|
||||
op.min_points = nb_pts / 2;
|
||||
op.epsilon = 0.02;
|
||||
op.cluster_epsilon = 0.05;
|
||||
op.normal_threshold = 0.8;
|
||||
|
||||
Pwn_vector points;
|
||||
|
||||
generate_random_points (Point (0., 0., 0.), vx, vy,
|
||||
5000, std::back_inserter (points));
|
||||
generate_random_points (Point (0., 0., 0.), vx, vz,
|
||||
5000, std::back_inserter (points));
|
||||
generate_random_points (Point (0., 0., 0.), vy, vz,
|
||||
5000, std::back_inserter (points));
|
||||
generate_random_points (Point (0., 0., 1.), vx, vy,
|
||||
5000, std::back_inserter (points));
|
||||
generate_random_points (Point (0., 1., 0.), vx, vz,
|
||||
5000, std::back_inserter (points));
|
||||
generate_random_points (Point (1., 0., 0.), vy, vz,
|
||||
5000, std::back_inserter (points));
|
||||
|
||||
|
||||
ransac.set_input(points);
|
||||
ransac.detect(op);
|
||||
Efficient_ransac::Plane_range planes = ransac.planes();
|
||||
|
||||
Points_with_structure pss (points, Point_map(), Normal_map(),
|
||||
planes,
|
||||
CGAL::Shape_detection_3::Plane_map<Traits>(),
|
||||
CGAL::Shape_detection_3::Point_to_shape_index_map<Traits>(points, planes),
|
||||
op.cluster_epsilon);
|
||||
|
||||
|
||||
std::vector<Point> vertices;
|
||||
|
||||
for (std::size_t i = 0; i < pss.size(); ++ i)
|
||||
{
|
||||
std::vector<Plane> planes;
|
||||
pss.adjacency (i, std::back_inserter (planes));
|
||||
if (planes.size () == 3)
|
||||
vertices.push_back (pss.point (i));
|
||||
}
|
||||
|
||||
if (vertices.size () != 8)
|
||||
{
|
||||
std::cerr << "Error: 8 point should have been structural vertices." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::vector<Point> ground_truth;
|
||||
ground_truth.push_back (Point (0., 0., 0.));
|
||||
ground_truth.push_back (Point (0., 0., 1.));
|
||||
ground_truth.push_back (Point (0., 1., 0.));
|
||||
ground_truth.push_back (Point (0., 1., 1.));
|
||||
ground_truth.push_back (Point (1., 0., 0.));
|
||||
ground_truth.push_back (Point (1., 0., 1.));
|
||||
ground_truth.push_back (Point (1., 1., 0.));
|
||||
ground_truth.push_back (Point (1., 1., 1.));
|
||||
std::vector<bool> found (ground_truth.size(), false);
|
||||
std::size_t nb_found = 0;
|
||||
|
||||
for (std::size_t i = 0; i < vertices.size(); ++ i)
|
||||
for (std::size_t j = 0; j < ground_truth.size(); ++ j)
|
||||
{
|
||||
if (found[j])
|
||||
continue;
|
||||
|
||||
if (CGAL::squared_distance (ground_truth[j], vertices[i]) < 1e-6)
|
||||
{
|
||||
found[j] = true;
|
||||
++ nb_found;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nb_found != ground_truth.size())
|
||||
{
|
||||
std::cerr << "Error: the following vert(ex/ices) was/were not found:" << std::endl;
|
||||
for (std::size_t i = 0; i < ground_truth.size(); ++ i)
|
||||
if (!(found[i]))
|
||||
std::cerr << " * " << ground_truth[i] << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,44 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/vcm_estimate_normals.h>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef CGAL::Point_3<Kernel> Point_3;
|
||||
typedef CGAL::Vector_3<Kernel> Vector_3;
|
||||
typedef std::pair<Point_3, Vector_3> PointWithNormal;
|
||||
|
||||
int main (void) {
|
||||
// Generate points on a plane
|
||||
int k = 100;
|
||||
double r = 10;
|
||||
|
||||
std::vector<PointWithNormal> points;
|
||||
points.push_back(std::make_pair(Point_3(0, 0, 0), Vector_3(0, 0, 0)));
|
||||
for (int i = 0; i < k; ++i) {
|
||||
double theta = 2 * i * CGAL_PI / k;
|
||||
points.push_back(std::make_pair(Point_3(r * cos(theta), r * sin(theta), 0),
|
||||
Vector_3(0, 0, 0)));
|
||||
}
|
||||
|
||||
// Estimate the normals using VCM
|
||||
double R = 20;
|
||||
vcm_estimate_normals(points.begin(), points.end(),
|
||||
CGAL::First_of_pair_property_map<PointWithNormal>(),
|
||||
CGAL::Second_of_pair_property_map<PointWithNormal>(),
|
||||
R, 0.0);
|
||||
|
||||
std::cout << "Normal is " << points[0].second << std::endl;
|
||||
|
||||
// The normal at the origin should be (0, 0, 1)
|
||||
double epsilon=2e-5;
|
||||
assert(points[0].second.x() < epsilon && points[0].second.x() > -epsilon);
|
||||
assert(points[0].second.y() < epsilon && points[0].second.y() > -epsilon);
|
||||
assert(points[0].second.z() < 0 || (points[0].second.z() < 1+epsilon && points[0].second.z() > 1-epsilon));
|
||||
assert(points[0].second.z() > 0 || (points[0].second.z() < -1+epsilon && points[0].second.z() > -1-epsilon));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
data/sphere_20k.xyz
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
#define CGAL_NO_DEPRECATION_WARNINGS
|
||||
|
||||
// wlop_simplify_and_regularize_test.cpp
|
||||
|
||||
//----------------------------------------------------------
|
||||
// Test the wlop simplify and regularize method:
|
||||
// Input format is .xyz.
|
||||
// No output.
|
||||
//----------------------------------------------------------
|
||||
// wlop_simplify_and_regularize_test points1.xyz points2.xyz...
|
||||
|
||||
// CGAL
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Real_timer.h>
|
||||
#include <CGAL/Memory_sizer.h>
|
||||
#include <CGAL/tags.h>
|
||||
|
||||
// This package
|
||||
#include <CGAL/wlop_simplify_and_regularize_point_set.h>
|
||||
#include <CGAL/IO/read_xyz_points.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// kernel
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
|
||||
// Simple geometric types
|
||||
typedef Kernel::FT FT;
|
||||
typedef Kernel::Point_3 Point;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Removes outliers
|
||||
template<typename Concurrency_tag>
|
||||
void test_wlop_simplify_and_regularize(
|
||||
std::vector<Point>& points, // input point set
|
||||
std::vector<Point>& output,
|
||||
double retain_percentage, // percentage of points to remove
|
||||
double neighbor_radius, // neighborhood size
|
||||
unsigned int iter_number, // iteration number
|
||||
bool need_compute_density)
|
||||
|
||||
{
|
||||
CGAL::Real_timer task_timer; task_timer.start();
|
||||
std::cerr << "Running WLOP simplify and regularize, (retain_percentage: "
|
||||
<< retain_percentage << "%, neighbor_radius="
|
||||
<< neighbor_radius << ")...\n";
|
||||
|
||||
// Make room for sample points
|
||||
std::vector<Point> points_sampled;
|
||||
points_sampled.resize(static_cast<std::size_t>(points.size() * (retain_percentage / 100.)));
|
||||
|
||||
output.clear();
|
||||
// Run algorithm
|
||||
CGAL::wlop_simplify_and_regularize_point_set<Concurrency_tag>(
|
||||
points.begin(),
|
||||
points.end(),
|
||||
std::back_inserter(output),
|
||||
retain_percentage,
|
||||
neighbor_radius,
|
||||
iter_number,
|
||||
need_compute_density);
|
||||
|
||||
output.clear();
|
||||
|
||||
std::size_t memory = CGAL::Memory_sizer().virtual_size();
|
||||
std::cerr << "ok: " << task_timer.time() << " seconds, "
|
||||
<< (memory>>20) << " Mb allocated"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// main()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
std::cerr << "WLOP simplify and regularize" << std::endl;
|
||||
|
||||
//***************************************
|
||||
// decode parameters
|
||||
//***************************************
|
||||
|
||||
// usage
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cerr << "For each input point set, apply WLOP algorithm.\n";
|
||||
std::cerr << "\n";
|
||||
std::cerr << "Usage: " << argv[0] << " file1.xyz file2.xyz..." << std::endl;
|
||||
std::cerr << "Input file format is .xyz.\n";
|
||||
std::cerr << "No output" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Algorithm parameters
|
||||
const double retain_percentage = 2; // percentage of points to retain.
|
||||
const double neighbor_radius = 0.5; // neighbors size.
|
||||
const unsigned int iter_number = 25; // number of iterations.
|
||||
const bool need_compute_density = false; // if needed to compute density.
|
||||
|
||||
// Accumulated errors
|
||||
int accumulated_fatal_err = EXIT_SUCCESS;
|
||||
|
||||
// Process each input file
|
||||
for(int i=1; i<argc; i++)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
|
||||
//***************************************
|
||||
// Loads point set
|
||||
//***************************************
|
||||
|
||||
// File name is:
|
||||
std::string input_filename = argv[i];
|
||||
|
||||
// Reads the point set file in points[].
|
||||
std::vector<Point> points;
|
||||
std::cerr << "Opening " << input_filename << " for reading..." << std::endl;
|
||||
|
||||
// If XYZ file format:
|
||||
std::ifstream stream(input_filename.c_str());
|
||||
if(stream &&
|
||||
CGAL::read_xyz_points(stream, std::back_inserter(points)))
|
||||
{
|
||||
std::cerr << "ok (" << points.size() << " points)" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Error: cannot read file " << input_filename << std::endl;
|
||||
accumulated_fatal_err = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
//***************************************
|
||||
// Test
|
||||
//***************************************
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
std::vector<Point> points2(points);
|
||||
#endif
|
||||
std::vector<Point> output;
|
||||
test_wlop_simplify_and_regularize<CGAL::Sequential_tag>(
|
||||
points, output, retain_percentage, neighbor_radius,
|
||||
iter_number, need_compute_density);
|
||||
|
||||
#ifdef CGAL_LINKED_WITH_TBB
|
||||
output.clear();
|
||||
test_wlop_simplify_and_regularize<CGAL::Parallel_tag>(
|
||||
points2, output, retain_percentage, neighbor_radius,
|
||||
iter_number, need_compute_density);
|
||||
#endif // CGAL_LINKED_WITH_TBB
|
||||
|
||||
|
||||
} // for each input file
|
||||
|
||||
std::cerr << std::endl;
|
||||
// Returns accumulated fatal error
|
||||
std::cerr << "Tool returned " << accumulated_fatal_err << std::endl;
|
||||
return accumulated_fatal_err;
|
||||
}
|
||||
Loading…
Reference in New Issue