Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder
Chronological Thread
- From: "Sebastien Loriot (GeometryFactory)" <>
- To:
- Subject: Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder
- Date: Wed, 22 Jan 2014 11:48:31 +0100
- Organization: GeometryFactory
Converting a Delaunay_triangulation_3 into a Polyhedron_3 makes no
sense (a 3D mesh of a convex hull is not a polyhedral surface).
However, converting a triangulated surface embedded into a
triangulation does.
What are you trying to do?
Sebastien.
On 01/20/2014 10:45 AM, Steven G wrote:
Dear CGAL users,
I want to convert an object of type Delaunay_triangulation_3 into a
Polyhedron_3, just like several other users of this forum. From their posts
and the given answers, I tried to use the Polyhedron_incremental_builder_3
to accomplish this. I make an indexed list of vertices, then only consider
the facets incident to the infinite vertex since I just want the hull of the
triangulation to make the Polyhedron. See the example code below.
I would like to stress that the Polyhedron I ultimately want is non-convex.
--------------------------------------------------------------------------------
-------------------------Example------------------------------------------
--------------------------------------------------------------------------------
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/Polyhedron_3.h>
#include<CGAL/IO/Polyhedron_iostream.h>
#include<fstream>
#include<vector>
#include<string>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel
K;
typedef CGAL::Polyhedron_3<K>
Polyhedron;
typedef Polyhedron::HalfedgeDS
HalfedgeDS;
typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, K>
Vb;
typedef CGAL::Triangulation_data_structure_3<Vb>
Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds>
Delaunay;
typedef Delaunay::Point
Point;
typedef Delaunay::Vertex_iterator
vertex_iterator;
typedef Delaunay::Facet_iterator
facet_iterator;
// Auxiliary function to test whether the new facet shares a halfedge with
one of the facets already added. If this is the case, return false, else
return true
bool test_new_point(int matrix [][3], int i) {
for(int k=0; k<i; k++) {
for(int l=0; l<=2; l++) {
if(matrix[i][0] == matrix[k][l] &&
matrix[i][1] ==
matrix[k][(l+1)%3]) return false;
if(matrix[i][1] == matrix[k][l] &&
matrix[i][2] ==
matrix[k][(l+1)%3]) return false;
if(matrix[i][2] == matrix[k][l] &&
matrix[i][0] ==
matrix[k][(l+1)%3]) return false;
}
}
return true;
}
// A modifier creating a triangle with the incremental builder.
template<class HDS>
class polyhedron_builder : public CGAL::Modifier_base<HDS> {
public:
polyhedron_builder() {}
void operator()( HDS& hds) {
typedef typename HDS::Vertex Vertex;
typedef typename Vertex::Point Point;
// Create a Delaunay triangulation with a number of points and their indices
std::vector< std::pair<Point,unsigned> > points;
Delaunay T;
// Create incremental builder and initialise polyhedron
CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true);
B.begin_surface(16,48);
// Add a number of points (in this case manually) into the DT and into
Polyhedron
points.push_back(std::make_pair(Point(0,0,0),0));
B.add_vertex(Point(0,0,0));
points.push_back(std::make_pair(Point(1,0,0),1));
B.add_vertex(Point(1,0,0));
points.push_back(std::make_pair(Point(0,1,0),2));
B.add_vertex(Point(0,1,0));
points.push_back(std::make_pair(Point(1,1,0),3));
B.add_vertex(Point(1,1,0));
points.push_back(std::make_pair(Point(0,0,1),4));
B.add_vertex(Point(0,0,1));
points.push_back(std::make_pair(Point(1,0,1),5));
B.add_vertex(Point(1,0,1));
points.push_back(std::make_pair(Point(0,1,1),6));
B.add_vertex(Point(0,1,1));
points.push_back(std::make_pair(Point(1,1,1),7));
B.add_vertex(Point(1,1,1));
points.push_back(std::make_pair(Point(0,0,2),8));
B.add_vertex(Point(0,0,2));
points.push_back(std::make_pair(Point(0,1,2),9));
B.add_vertex(Point(0,1,2));
points.push_back(std::make_pair(Point(1,0,2),10));
B.add_vertex(Point(1,0,2));
points.push_back(std::make_pair(Point(1,1,2),11));
B.add_vertex(Point(1,1,2));
points.push_back(std::make_pair(Point(2,0,2),12));
B.add_vertex(Point(2,0,2));
points.push_back(std::make_pair(Point(2,0,1),13));
B.add_vertex(Point(2,0,1));
points.push_back(std::make_pair(Point(2,1,2),14));
B.add_vertex(Point(2,1,2));
points.push_back(std::make_pair(Point(2,1,1),15));
B.add_vertex(Point(2,1,1));
T.insert( points.begin(),points.end() );
// Add the polyhedron triangles
int A [80][3];
int i = 0;
int tmp;
for(facet_iterator fct = T.facets_begin(); fct !=
T.facets_end(); ++fct) {
if (T.is_infinite(*fct)){
// Only consider facets on the outside of
the triangulation
for (int k = 1; k <=3; ++k) {
A[i][k-1] =
fct->first->vertex((fct->second+k)%4)->info();
}
if (!(test_new_point(A,i))) { //
If new facet shares a halfedge with a
facet previously added, reverse order of vertices
tmp = A[i][1] ;
A[i][1]=A[i][2]; A[i][2]=tmp;
}
if (!(A[i][0] == A[i][1] || A[i][0] ==
A[i][2] || A[i][1] == A[i][2])
&& test_new_point(A,i) ) {
B.begin_facet();
for (int j = 0; j <=2; j++) {
std::cout << A[i][j] << "\t";
B.add_vertex_to_facet(
A[i][j] );
}
B.end_facet();
std::cout << "--" << std::endl;
}
i++;
}
}
// Finish creation of the polyhedron
B.end_surface();
}
};
int main() {
Polyhedron P;
polyhedron_builder<HalfedgeDS> builder;
P.delegate( builder );
std::cout << "Number of vertices: " << P.size_of_vertices() << std::endl;
std::cout << "Number of facets:" << P.size_of_facets() << std::endl;
std::ofstream os("test.off");
os << P;
os.close();
return 0;
}
----------------------------------------------------------------
The output I get is the following:
15 7 0 --
7 3 0 --
0 3 15 --
2 0 6
CGAL::Polyhedron_incremental_builder_3<HDS>::lookup_hole(): input error: at
vertex 0 a closed surface already exists and facet 3 is nonetheless
adjacent.
The closed cycle of facets is: 2 1 0.
--
(...)
(Some other points follow, many having 0 as a vertex index, ending with a
segmentation fault.)
I see that there are too many facets having '0' as a vertex, but I don't
know how to solve this problem. It seems that using the facets of the DT
gives rise to more mistakes, for example the issue with the shared halfedges
which I had to solve first.
Can someone give me a clue on how to solve this, maybe present an
alternative way to correctly build a polyhedron from a DT?
Thank you.
Cheers,
Steven G
--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Construction-errors-using-the-Polyhedron-3-incremental-builder-tp4658678.html
Sent from the cgal-discuss mailing list archive at Nabble.com.
- [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Steven G, 01/20/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Sebastien Loriot (GeometryFactory), 01/22/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Guillaume Damiand, 01/23/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Steven G, 01/23/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Sebastien Loriot (GeometryFactory), 01/23/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Steven G, 01/23/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Guillaume Damiand, 01/23/2014
- Re: [cgal-discuss] Construction errors using the Polyhedron_3 incremental builder, Sebastien Loriot (GeometryFactory), 01/22/2014
Archive powered by MHonArc 2.6.18.