Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gsoc2023 constraint based point cloud denoising #7897

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
497136b
setup empty file + example
wwwenwilliam Jun 16, 2023
7dd8745
high level notes
wwwenwilliam Jun 16, 2023
a836d9a
first implementation of calculate nvt, still needs to be tested
wwwenwilliam Jun 23, 2023
e1c34cb
add beo
wwwenwilliam Jun 24, 2023
c198260
normals are being moved but is buggy
wwwenwilliam Jun 27, 2023
a038b83
progress on implementation
wwwenwilliam Jun 30, 2023
c94de3e
get the program to stop crashing
wwwenwilliam Jun 30, 2023
6420348
feature detection still not fixed but pushing anyway for update meeti…
wwwenwilliam Jul 14, 2023
5e7ec88
incremental debugging
wwwenwilliam Jul 15, 2023
e848bb7
small bug fix that still doesnt change anything??
wwwenwilliam Jul 16, 2023
2633b00
feature detection fixed? and add edge point smoothing
wwwenwilliam Jul 24, 2023
886d155
add colours to points
wwwenwilliam Aug 3, 2023
e14d677
rewrite of algorithm + automatic parameters
wwwenwilliam Aug 6, 2023
d1095a4
small fixes + two eigenvalue thresholds
wwwenwilliam Aug 11, 2023
873e3d0
parameter tuning
wwwenwilliam Aug 23, 2023
b173ba3
use cgal average spacing and move eigenvalue optimization to own func…
wwwenwilliam Sep 3, 2023
fa8ea5a
auto calculate diameter of point set
wwwenwilliam Sep 4, 2023
fe54b25
final bit of tuning + small code improvements
wwwenwilliam Sep 23, 2023
5f5c6ab
delete first version of implementation and replace with second
wwwenwilliam Sep 23, 2023
1d86a72
light docs for internal stuff
wwwenwilliam Sep 23, 2023
4a46295
add test for constraint based smoothing
wwwenwilliam Sep 23, 2023
685bb50
mean error to mean squared error + final tuning for test
wwwenwilliam Sep 27, 2023
ea31c4a
Update Point_set_processing_3/include/CGAL/constraint_based_smooth_po…
soesau Nov 30, 2023
2abfec1
replacing Eigen by DiagonalizeTraits
soesau May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ if(TARGET CGAL::Eigen3_support)
foreach(
target
jet_smoothing_example
constraint_based_smoothing_example
normal_estimation
clustering_example
edges_example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#include <CGAL/Simple_cartesian.h>

#include <CGAL/constraint_based_smooth_point_set.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/property_map.h>
#include <CGAL/tags.h>

#include <utility> // defines std::pair
#include <string>
#include <fstream>
#include <chrono>

// Types
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;
typedef std::array<unsigned char, 3> Color;

typedef std::tuple<Point, Vector, Color> PNC;
typedef CGAL::Nth_of_tuple_property_map<0, PNC> Point_map;
typedef CGAL::Nth_of_tuple_property_map<1, PNC> Normal_map;
typedef CGAL::Nth_of_tuple_property_map<2, PNC> Color_map;

// Concurrency
typedef CGAL::Parallel_if_available_tag Concurrency_tag;

// Define how a color should be stored
namespace CGAL {

template< class F >
struct Output_rep< ::Color, F > {
const ::Color& c;
static const bool is_specialized = true;
Output_rep (const ::Color& c) : c(c)
{ }
std::ostream& operator() (std::ostream& out) const
{
if (IO::is_ascii(out))
out << int(c[0]) << " " << int(c[1]) << " " << int(c[2]);
else
out.write(reinterpret_cast<const char*>(&c), sizeof(c));
return out;
}
};

} // namespace CGAL

int main(int argc, char*argv[])
{
const std::string input_filename = (argc>1) ? argv[1] : CGAL::data_file_path("points_3/fin90_with_PCA_normals.xyz");
const char* output_filename = (argc>2) ? argv[2] : "data/fin90_with_PCA_normals_constraint_based_smoothed.ply";

// Reads a point set file in points[] * with normals *.
std::vector<PNC> points;
if(!CGAL::IO::read_points(input_filename, std::back_inserter(points),
CGAL::parameters::point_map(CGAL::Nth_of_tuple_property_map<0, PNC>())
.normal_map(CGAL::Nth_of_tuple_property_map<1, PNC>())))
{
std::cerr << "Error: cannot read file " << input_filename << std::endl;
return EXIT_FAILURE;
}

// Algorithm parameters
const int iter_number = 25;

auto start = std::chrono::high_resolution_clock::now();

for(int i = 0; i < iter_number; ++i)
{
auto curr_start = std::chrono::high_resolution_clock::now();
/* double error = */
CGAL::constraint_based_smooth_point_set <Concurrency_tag>(
points,
CGAL::parameters::point_map(CGAL::Nth_of_tuple_property_map<0, PNC>())
.normal_map(CGAL::Nth_of_tuple_property_map<1, PNC>()));

std::cout << i << std::endl;

auto curr_stop = std::chrono::high_resolution_clock::now();
std::cout << "Iteration time (ms): " << std::chrono::duration_cast<std::chrono::milliseconds>(curr_stop - curr_start).count() << std::endl;

std::cout << "iterations/iteration_" + std::to_string(i) + ".ply" << std::endl;
std::ofstream f("data/iterations/iteration_" + std::to_string(i) + ".ply", std::ios::binary);
CGAL::IO::set_binary_mode(f); // The PLY file will be written in the binary format
if(!CGAL::IO::write_PLY_with_properties(f, points,
CGAL::make_ply_point_writer (Point_map()),
CGAL::make_ply_normal_writer(Normal_map()),
std::make_tuple(Color_map(),
CGAL::IO::PLY_property<unsigned char>("red"),
CGAL::IO::PLY_property<unsigned char>("green"),
CGAL::IO::PLY_property<unsigned char>("blue"))))
{
return EXIT_FAILURE;
}

}

auto stop = std::chrono::high_resolution_clock::now();

for(size_t i=0;i<points.size();++i){
Color c = get<2>(points[i]);
// std::cout << int(c[0]) << " " << int(c[1]) << " " << int(c[2]) << std::endl;
}

std::cout << "Average iteration time (ms): " << std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count() / iter_number << std::endl;

//// Save point set.
// if(!CGAL::IO::write_XYZ(output_filename, points,
// CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())
// .normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>())
// .stream_precision(17)))
// return EXIT_FAILURE;

std::ofstream f(output_filename, std::ios::binary);
CGAL::IO::set_binary_mode(f); // The PLY file will be written in the binary format
if(!CGAL::IO::write_PLY_with_properties(f, points,
CGAL::make_ply_point_writer (Point_map()),
CGAL::make_ply_normal_writer(Normal_map()),
std::make_tuple(Color_map(),
CGAL::IO::PLY_property<unsigned char>("red"),
CGAL::IO::PLY_property<unsigned char>("green"),
CGAL::IO::PLY_property<unsigned char>("blue"))))
{
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}
Loading