Subject: CGAL users discussion list
List archive
- From: "David" <>
- To: <>
- Subject: RE: [cgal-discuss] Additional Facets
- Date: Wed, 6 Dec 2006 07:00:56 +0100
Thanks for help Peter, but...
The display is good, but when I use a little bit more complicated
operations, these additional facets seems to really exists.
This is really poor code (I'm just beginning in use of CGAL).
The goal is to make volumes from facets.
If you compile this code and rotate the volume, you'll see these 2 facets in
the back.
Am I doing wrong operations, or is it another thing?
Thanks.
David
#include "CGAL/basic.h"
#include <CGAL/Gmpz.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Convex_hull_traits_3.h>
#include <CGAL/convex_hull_3.h>
#include <CGAL/Vector_3.h>
#include <vector>
#include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
#include <CGAL/IO/Qt_widget_Nef_3.h>
#include <qapplication.h>
typedef CGAL::Homogeneous<CGAL::Gmpz> Kernel;
typedef Kernel::RT RT;
typedef CGAL::Nef_polyhedron_3<Kernel> Poly3D;
typedef CGAL::Point_3<Kernel> Point3D;
typedef CGAL::Polyhedron_3<Kernel> Polyh3D1;
typedef Kernel::Vector_3 Vector3D;
///////////////////////////////////////////////////////////////////////////
Poly3D MakeVol(Point3D a, Point3D b)
{
CGAL::Iso_cuboid_3<Kernel> cube(a,b);
CGAL::Object ch_object;
CGAL::Polyhedron_3<Kernel> p0;
std::vector<Point3D> points;
p0.clear();
points.clear();
for(int i=0;i<8;i++) points.push_back(cube.vertex(i));
CGAL::convex_hull_3(points.begin(), points.end(), ch_object);
if(CGAL::assign(p0, ch_object)!=true) {
std::cout << "p0: convex hull error!" << std::endl;
return(Poly3D());
}
return(Poly3D(p0));
}
///////////////////////////////////////////////////////////////////////////
Poly3D MakeVol(std::list<Point3D>::iterator first,
std::list<Point3D>::iterator last)
{
CGAL::Object ch;
CGAL::convex_hull_3(first,last,ch);
Polyh3D1 p;
p.clear();
if(CGAL::assign(p,ch)!=true) {
std::cout << "p: convex hull error!" << std::endl;
return(Poly3D());
}
return(Poly3D(p));
}
///////////////////////////////////////////////////////////////////////////
// file: examples/Polyhedron/polyhedron_prog_normals.C page 831
Vector3D Normal(Polyh3D1::Facet_iterator &f)
{
Polyh3D1::Facet::Halfedge_handle h=(*f).halfedge();
Vector3D v=CGAL::cross_product(
h->next()->vertex()->point() - h->vertex()->point(),
h->next()->next()->vertex()->point() - h->next()->vertex()->point());
CGAL::Gmpz v2=sqrt(v.hx()*v.hx()+v.hy()*v.hy()+v.hz()*v.hz());
return(Vector3D(v.hx()/v2, v.hy()/v2, v.hz()/v2));
}
///////////////////////////////////////////////////////////////////////////
Vector3D Neg(const Vector3D& v)
{
return(Vector3D(-v.hx(), -v.hy(), -v.hz()));
}
///////////////////////////////////////////////////////////////////////////
Vector3D MultVS(const Vector3D& v, const CGAL::Gmpz& s)
{
return(Vector3D(v.hx()*s,v.hy()*s,v.hz()*s));
}
///////////////////////////////////////////////////////////////////////////
Point3D AddVP(const Vector3D& v, const Point3D& p)
{
return(Point3D(v.hx()+p.hx(),v.hy()+p.hy(),v.hz()+p.hz()));
}
///////////////////////////////////////////////////////////////////////////
std::list<Poly3D*> MakeHollow(Poly3D& b, CGAL::Gmpz t)
{
std::list<Poly3D*> list;
Polyh3D1 P;
b.convert_to_Polyhedron(P);
Polyh3D1::Facet_iterator it;
for(it=P.facets_begin(); it!=P.facets_end(); ++it) {
Vector3D v=Normal(it);
Polyh3D1::Facet::Halfedge_handle h = (*it).halfedge();
Polyh3D1::Facet::Halfedge_handle h0=h;
Point3D p;
std::list<Point3D> list2;
list2.clear();
do {
p=h->vertex()->point();
Point3D p1(AddVP(MultVS(v,t),p));
list2.push_back(p1);
Point3D p2(AddVP(Neg(MultVS(v,t)),p));
list2.push_back(p2);
if(h->next()==0) break;
h=h->next();
if(h==h0) break;
} while(true);
Poly3D* b0=new Poly3D(MakeVol(list2.begin(), list2.end()));
list.push_back(b0);
}
return(std::list<Poly3D*>(list));
}
///////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
Poly3D b1=MakeVol(Point3D(1,1,1), Point3D(10,10,10));
Poly3D b2=MakeVol(Point3D(1,1,9), Point3D(20,20,20));
Poly3D b3=b1.join(b2);
std::list<Poly3D*> l=MakeHollow(b3,1);
Poly3D b5;
b5.clear();
std::list<Poly3D*>::iterator it;
for(it=l.begin(); it!=l.end(); it++) {
b5=b5+(**it);
}
QApplication a(argc, argv);
CGAL::Qt_widget_Nef_3<Poly3D>* w =
new CGAL::Qt_widget_Nef_3<Poly3D>(b5);
a.setMainWidget(w);
w->show();
return a.exec();
}
- CGAL::Arr_conic_traits_2 with LEDA traits?, tm05855, 12/05/2006
- RE: [cgal-discuss] Additional Facets, David, 12/06/2006
- RE: [cgal-discuss] Additional Facets, Peter Hachenberger, 12/06/2006
- RE: RE: [cgal-discuss] Additional Facets, David, 12/06/2006
- RE: [cgal-discuss] Additional Facets, Peter Hachenberger, 12/06/2006
- <Possible follow-up(s)>
- RE: CGAL::Arr_conic_traits_2 with LEDA traits?, Marcel Janer, 12/06/2006
- RE: [cgal-discuss] Additional Facets, David, 12/06/2006
Archive powered by MHonArc 2.6.16.