Skip to content

Instantly share code, notes, and snippets.

@afabri
Created February 8, 2021 14:56
Show Gist options
  • Save afabri/a8c248195c6fe11d50258e951d2163ee to your computer and use it in GitHub Desktop.
Save afabri/a8c248195c6fe11d50258e951d2163ee to your computer and use it in GitHub Desktop.
Poisson for Petras
# This is the CMake script for compiling this folder.
cmake_minimum_required(VERSION 3.1...3.15)
project( Poisson )
# Find CGAL
find_package(CGAL QUIET)
if ( CGAL_FOUND )
# VisualC++ optimization for applications dealing with large data
if (MSVC)
# Allow Windows 32bit applications to use up to 3GB of RAM
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
# Print new compilation options
message( STATUS "USING DEBUG CXXFLAGS = '${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}'" )
message( STATUS "USING DEBUG EXEFLAGS = '${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG}'" )
message( STATUS "USING RELEASE CXXFLAGS = '${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}'" )
message( STATUS "USING RELEASE EXEFLAGS = '${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}'" )
endif()
# Find Eigen3 (requires 3.1.0 or greater)
find_package(Eigen3 3.1.0)
include(CGAL_Eigen3_support)
if (TARGET CGAL::Eigen3_support)
# Executables that require Eigen 3
create_single_source_cgal_program( "poisson.cpp" )
target_link_libraries(poisson PUBLIC CGAL::Eigen3_support)
else()
message(STATUS "NOTICE: The examples need Eigen 3.1 (or greater) will not be compiled.")
endif()
else()
message(STATUS "NOTICE: This program requires the CGAL library, and will not be compiled.")
endif()
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Point_set_3/IO.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/compute_average_spacing.h>
#include <CGAL/poisson_surface_reconstruction.h>
#include <CGAL/Polyhedron_3.h>
#include <vector>
#include <string>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel2;
typedef Kernel2::Point_3 Point2;
typedef Kernel2::Vector_3 Vector2;
typedef CGAL::Polyhedron_3<Kernel2> Polyhedron2;
int main()
{
CGAL::Point_set_3<Kernel2::Point_3, Kernel2::Vector_3> points;
std::ifstream input("Clouds/Cloud1.ply");
std::string comment;
if(! CGAL::read_ply_point_set(input,points, comment)){
std::cerr << "Cannot read" << std::endl;
}
Polyhedron2 output_mesh;
double average_spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag>(points, 6);
CGAL::poisson_surface_reconstruction_delaunay (points.begin (), points.end (), points.point_map() , points.normal_map(), output_mesh, average_spacing);
std::ofstream out("Cloud1.off");
out.precision(17);
out << output_mesh << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment