Last active
January 18, 2021 13:30
-
-
Save petrasvestartas/7d84b73170fafa38c51b23ad699af5d4 to your computer and use it in GitHub Desktop.
CGAL Poisson Reconstruction CPP file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef CGAL::Simple_cartesian<double> Kernel; | |
typedef Kernel::Point_3 Point; | |
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; | |
typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor; | |
typedef Polyhedron::HalfedgeDS HalfedgeDS; | |
// Normal Estimation Types | |
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel2; | |
typedef Kernel::Point_3 Point2; | |
typedef Kernel::Vector_3 Vector2; | |
typedef std::pair<Kernel2::Point_3, Kernel2::Vector_3> PointVectorPair; // Point with normal vector stored in a std::pair. | |
typedef CGAL::Parallel_if_available_tag Concurrency_tag;// Concurrency | |
typedef CGAL::Polyhedron_3<Kernel2> Polyhedron2; | |
typedef CGAL::Polyhedron_3<Kernel2, CGAL::Polyhedron_items_with_id_3> Polyhedron3; | |
PINVOKE void ComputePoissonSurfaceReconstruction ( | |
double* p, size_t p_c, | |
double* n, size_t n_c, | |
double* c, size_t c_c, | |
double radius,// = 0.1, | |
int iterations,// = 30, | |
int neighbours,// = 100, //reorientation | |
double*& p_o, int& p_c_o, | |
double*& n_o, int& n_c_o, | |
double*& c_o, int& c_c_o | |
){ | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//Convert Input to CGAL PointCloud | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
std::list<PointVectorPair> points; | |
if(p_c<9)return; | |
for ( int i = 0; i < p_c; i++ ) { | |
points.push_back (PointVectorPair ( | |
Kernel2::Point_3 (p[3 * i + 0], p[3 * i + 1], p[3 * i + 2]), | |
Kernel2::Vector_3 (n[3 * i + 0], n[3 * i + 1], n[3 * i + 2]) | |
)); | |
} | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//Run CGAL Method | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
try { | |
Polyhedron3 output_mesh; | |
double average_spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag> (points, 6, CGAL::parameters::point_map (CGAL::First_of_pair_property_map<PointVectorPair> ())); | |
if ( CGAL::poisson_surface_reconstruction_delaunay (points.begin (), points.end (), CGAL::First_of_pair_property_map<PointVectorPair> (), CGAL::Second_of_pair_property_map<PointVectorPair> (), output_mesh, average_spacing) ) { | |
p_c_o = output_mesh.size_of_vertices () * 3; | |
p_o = new double[p_c_o]; | |
n_c_o = output_mesh.size_of_facets () * 3; | |
n_o = new double[n_c_o]; | |
c_c_o = output_mesh.size_of_vertices () * 3; | |
c_o = new double[c_c_o]; | |
std::size_t counter = 0; | |
for ( Polyhedron3::Vertex_iterator it = output_mesh.vertices_begin (); it != output_mesh.vertices_end (); ++it ) { | |
it->id () = counter++; | |
} | |
std::size_t counter2 = 0; | |
for ( Polyhedron3::Facet_iterator it = output_mesh.facets_begin (); it!= output_mesh.facets_end (); ++it ) { | |
it->id() = counter2++; | |
} | |
int i = 0; | |
int a = 0; | |
int c = 0; | |
for ( Polyhedron3::Vertex_iterator it = output_mesh.vertices_begin (); it != output_mesh.vertices_end (); ++it ){ | |
p_o[a++] = it->point ().x (); | |
p_o[a++] = it->point ().y (); | |
p_o[a++] = it->point ().z (); | |
c_o[c++] = 0; | |
c_o[c++] = 0; | |
c_o[c++] = 0; | |
} | |
////Requires CGAL 5.2 | |
//myfile2.open ("C:\\libs\\Cockroach\\CockroachPInvoke\\Cockroach_CSHARP_DLL\\bin\\x64\\PoissonStep2.txt"); | |
//for ( Polyhedron3::Facet_handle fh : output_mesh.face () ) { | |
// Polyhedron3::Halfedge_handle start = fh->halfedge (), h = start; | |
// do { | |
// std::cout << h->vertex ()->id () << "\n"; | |
// h = h->next (); | |
// } while ( h != start ); | |
//} | |
int b = 0; | |
for ( auto it = output_mesh.facets_begin (); it != output_mesh.facets_end (); ++it ) { | |
auto circ = it->facet_begin (); | |
do { | |
n_o[b++] = circ->vertex ()->id (); | |
} while ( ++circ != it->facet_begin () ); | |
} | |
} | |
} catch ( const std::exception& e ) { | |
std::ofstream myfile2; | |
myfile2.open ("C:\\libs\\Cockroach\\CockroachPInvoke\\Cockroach_CSHARP_DLL\\bin\\x64\\PoissonDebug.txt"); | |
myfile2<<e.what(); | |
myfile2.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This won't compile without the
#include