Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] Intersection of polyhedron - Visual hull and Gmpz float precision
Chronological Thread
- From: Cédric LE MAITRE <>
- To:
- Subject: Re: [cgal-discuss] Intersection of polyhedron - Visual hull and Gmpz float precision
- Date: Wed, 10 Jan 2007 14:10:58 +0100
Hi Peter,
I try your Visual hull demo. And it works very well.
I just try to export the resulting 3D model into a file. The file is then correctly exported with floating precision coordiantes.
But when i want to load this file in a polyhedron with this code:
#include <CGAL/Cartesian.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Gmpz.h>
#include <CGAL/Quotient.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/cartesian_homogeneous_conversion.h>
#include <fstream>
typedef CGAL::Gmpz NT;
typedef CGAL::Quotient<NT> CNT;
typedef CGAL::Cartesian<CNT> CKernel;
typedef CGAL::Homogeneous<NT> Kernel;
typedef CGAL::Cartesian<double> Kerneld;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::HalfedgeDS HalfedgeDS;
typedef CKernel::FT FT;
typedef CKernel::Point_3 CPoint;
typedef Kernel::Point_3 Point_3;
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Polyhedron_VRML_2_ostream.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
#include <iostream>
Polyhedron P;
std::ifstream inf("...");
std::istream* p_in;
p_in = &inf;
(*p_in) >> P;
This read the file but create a model with integer precision coordinate.
It seems to come from the use of CGAL::Gmpz type for the kernel. I don't find how to use this type of kernel, but it works in your demo to manipulate float precision.
Please, how do you use float precision with Gmpz ?
Thanks,
Cedric.
Peter Hachenberger a écrit :
Hi Cedric,
first, a Polyhedron_3 can be converted to a Nef_polyhedron_3, if the
Polyhedron is 2-manifold. That is not the case in your first example.
The second example uses the correct approach, but here you you need to
know is, that it is important how that the polyhedron is consistently
oriented counterclockwise. The tetrahedra in your example are oriented
clockwise. So, if you change
P.make_tetrahedron(p_top, p_center, p1, p2);
P.make_tetrahedron(p_top, p_center,p2, p3);
to
P.make_tetrahedron(p_top, p_center, p2, p1);
P.make_tetrahedron(p_top, p_center, p3 p2);
it works. If they are oriented clockwise, they are inside out. Then the union behaves like an intersection and the other way around.
Peter
On Tue, 2006-12-12 at 19:02 +0100, Cédric LE MAITRE wrote:
Hi Peter,
Sorry. i've seen lot of information in French on CGAL. That's why i
used French in my previous mail. Indeed, what i want to do is to compute a visual hull from 2d polygon
contour of silhouettes.
I haven't seen the demo that you've already done for visual hull. And
this is a good advice. I will have a look on it (after QT
installation...)
Concerning my problem with polyhedra intersection. i tried to convert
my polyhedra to Nef_Polyhedra. This works well with polyhedra of a simple 3d primitive (cube,
tetrahedron). But when i try on more complex polyhedron (like in the
next code), my program crashes.
i suppose it come of my polyhedron which is an union of tetrahedron
which compose my projection cone on the silhouette. So there are some
surface inside my polyhedra and maybe this is not compatible with
Nef_Polyhedra creation...
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Polyhedron_VRML_2_ostream.h> #include <CGAL/IO/Color.h>
#include <iostream>
#include <CGAL/Gmpz.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
typedef CGAL::Homogeneous<CGAL::Gmpz> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::Point_3 Point;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
int main() {
Point p_top(10.0f, 10.0f, 0.0f);
Point p_center(10.0f, 10.0f, -40.0f);
Point p1(20.0f, 5.0f, -40.0f);
Point p2(5.0f, 5.0f, -40.0f);
Point p3(5.0f, 30.0f, -40.0f);
Point p4(15.0f, 30.0f, -40.0f);
Point p5(25.0f, 10.0f, -40.0f);
Polyhedron P;
P.make_tetrahedron(p_top, p_center, p1, p2);
P.make_tetrahedron(p_top, p_center, p2, p3);
P.make_tetrahedron(p_top, p_center, p3, p4);
P.make_tetrahedron(p_top, p_center, p4, p5);
P.make_tetrahedron(p_top, p_center, p5, p1);
CGAL::VRML_2_ostream out( std::cout);
Nef_polyhedron N1(P); // it crashes
int t = N1.number_of_vertices ();
Polyhedron P1;
N1.convert_to_Polyhedron(P1);
//std::cout << P;
out << (Polyhedron)P1;
return (1);
}
So i try with the union of tetrahedra with the Nef_Polyhedron boolean
operation. But the union doesn't work. The union resulting polyhedron
have 0 vertice...
int main() {
Point p_top(10.0f, 10.0f, 0.0f);
Point p_center(10.0f, 10.0f, -40.0f);
Point p1(20.0f, 5.0f, -40.0f);
Point p2(5.0f, 5.0f, -40.0f);
Point p3(5.0f, 30.0f, -40.0f);
Point p4(15.0f, 30.0f, -40.0f);
Point p5(25.0f, 10.0f, -40.0f);
Polyhedron P;
P.make_tetrahedron(p_top, p_center, p1, p2);
Polyhedron P2;
P2.make_tetrahedron(p_top, p_center, p2, p3);
Nef_polyhedron N1(P);
int t = N1.number_of_vertices (); // returns 4
Nef_polyhedron N2(P2);
N1 += N2
int t2 = N1.number_of_vertices (); // returns 0
return (1);
}
Thanks a lot for helping me with my introduction into CGAL.
Regards,
Cedric LE MAITRE.
Peter Hachenberger a écrit :Hi Cedric,
my French is very bad, but I am in charge of the Nef polyehdra, so I try
to help you. Usually you should write in English to this mailing list.
First, you can do complex polyhedron intersections with
Nef_polyhedron_3. You can get a Nef_polyhedron from a Polyhedron
by using the constructor Nef_polyhedron_3(Polyhedron_3). It sounds like
you had some problems with that, but my French is not good enough to
understand them. If you can state your problems in English, I will
help you.
An advice. We already wrote a demo program for the visual hull. You can
find it in demo/Nef_3. Try to compile visual_hull.cpp and run it with
the given example mpi.vsh.
Best, Peter
On Tue, 2006-12-12 at 17:40 +0100, Cédric LE MAITRE wrote:
Bonjour,
Je suis novice avec la librairie CGAL et j'utilise pour la 1ere fois
cette mailing-list (je ne connais donc pas les uses et coutumes). En tout cas, j'utiliserais pour cela le Français pour communiquer. Et
mon message s'adresse à des développeur CGAL.
Je cherche à calculer un polyèdre correspondant l'intersection de 2
polyèdres 3D. Mes polyèdres sont des cones de vues constitués d'un
sommet et d'une base constituée de n points (correspondant à n points
d'un contour sur un plan. L'objectif final étant de reconstruire un
visual hull à partir de contour 2D de la silhouette d'une forme).
Voici mon code :
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Polyhedron_VRML_2_ostream.h> #include <iostream>
#include <CGAL/Gmpz.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
typedef CGAL::Homogeneous<CGAL::Gmpz> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::Point_3 Point;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
int main() {
Point p_top(10.0f, 10.0f, 0.0f);
Point p_center(10.0f, 10.0f, -40.0f);
Point p1(20.0f, 5.0f, -40.0f);
Point p2(5.0f, 5.0f, -40.0f);
Point p3(5.0f, 30.0f, -40.0f);
Point p4(15.0f, 30.0f, -40.0f);
Point p5(25.0f, 10.0f, -40.0f);
Polyhedron P;
P.make_tetrahedron(p_top, p_center, p1, p2);
P.make_tetrahedron(p_top, p_center, p2, p3);
P.make_tetrahedron(p_top, p_center, p3, p4);
P.make_tetrahedron(p_top, p_center, p4, p5);
P.make_tetrahedron(p_top, p_center, p5, p1);
Point p2_top(20.0f, 10.0f, -10.0f);
Point p2_center(-20.0f, 10.0f, -30.0f);
Point p21(-20.0f, 5.0f, 0.0f);
Point p22(-20.0f, 5.0f, -25.0f);
Point p23(-20.0f, 30.0f, -25.0f);
Point p24(-20.0f, 30.0f, -5.0f);
Point p25(-20.0f, 10.0f, 5.0f);
Polyhedron P2;
P2.make_tetrahedron(p2_top, p2_center, p21, p22);
P2.make_tetrahedron(p2_top, p2_center, p22, p23);
P2.make_tetrahedron(p2_top, p2_center, p23, p24);
P2.make_tetrahedron(p2_top, p2_center, p24, p25);
P2.make_tetrahedron(p2_top, p2_center, p25, p21);
CGAL::VRML_2_ostream out( std::cout);
out << (Polyhedron)P;
out << (Polyhedron)P2;
return (1);
}
J'y crée 2 polyèdre P et P2 (qui possède une zone d'intersection).
Mon problème est comment calculer le polyèdre d'intersection ?
J'ai essayé de le faire en utilisant la classe Nef_Polyedron et ces
opération booléenne. Or:
* il est impossible de créer un Nef_Polyhedron directement à
partir d'un Polyhedron tel que P et P2
* ex: Nef_polyhedron N1(P); -> plante CGAL
* idem lorsque j'assaie de créer un Nef_Polyhedron en faisant
l'union de tetrahedron (sans passer ?
* Ex: Nef_polyhedron N1(P_tetra); // Nb de vertices de
N1 résultat = 4
Nef_polyhedronN2(P_tetra2);
N1 += N2; // Nb de vertices de N1 résultat = 0 !!
Est-il possible de calculer l'intersection de polyèdre complexe avec
CGAL ?
Merci d'avance à toute les personnes qui prendront le temps de
répondre à mes questions.
Cédric.
______________________________________________________________________
- Re: [cgal-discuss] Intersection of polyhedron - Visual hull and Gmpz float precision, Cédric LE MAITRE, 01/10/2007
- Re: [cgal-discuss] Intersection of polyhedron - Visual hull and Gmpz float precision, Peter Hachenberger, 01/10/2007
Archive powered by MHonArc 2.6.16.