Subject: CGAL users discussion list
List archive
- From: "Mengda Wu" <>
- To:
- Cc: "Peter Hachenberger" <>
- Subject: Nef_polyhedron: cannot convert to an enriched polyhedron
- Date: Mon, 7 Apr 2008 00:47:33 -0700
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=Tb11g6jsleFVJ7rHSk5jAz+UKLlpvtn6GNKuyZfgg+CuTPO1f1mFZswgfEjSv8eUdkoptwfOWMPeWTR63OOZ6Hb4plqMqEU994TngdP+dik4/khfUq3/HloG4U+m4BZ3Bx8BFIkkuZvDfXcWPNrxHeObcjwFpUGIIh6oyjh71FU=
Sorry. I forgot to attach last time. Here it is.
Thanks,
Mengda
---------- Forwarded message ----------
From: Mengda Wu <>
Date: 2008-4-7 0:43
Subject: Nef_polyhedron: cannot convert to an enriched polyhedron
To:
Hi Peter,
Thanks a lot for your explanations. I am testing the results.
But I have an side problem because of which I cannot try the union operation.
I am using an enriched polyhedron, which enriches the contents of vertices,
halfedges, and facets in the polyhedron (see attach). But I cannot compile when
I try to use convert_to_Polyhedron function.
error C2664: 'CGAL::Nef_polyhedron_3<Kernel_>::convert_to_Polyhedron' : cannot convert parameter 1 from 'MyCGALprogram::Enriched_Polyhedron' to 'CGAL::Polyhedron_3<PolyhedronTraits_3> &
It seems that the Nef_polyhedron_3
has been hardcoded to use the CGAL::Polyhedron_3. Is there a way to get around of this?
Thanks,
Mengda
2008/4/5, Peter Hachenberger <>:
Hi Mengda,
in the latest CGAL version the Nef polyhedra are getting triangulated if
you convert them to polyhedral surfaces. If you want that conversion
anyway to put the resulting polyhedron out as an off file in the end,
then there should only be one problem. Not every Nef polyhedron can be
converted to a polyhedral surface. Look into the user manual for details
on that.
Peter
On Sat, 2008-04-05 at 14:59 -0700, Mengda Wu wrote:
> Hi there,
>
> I have two polyhedra which are triangular, manifold, and have one
> overlap region. I am wondering whether
> I can get a polyhedron which is union of the two, also triangular and
> manifold through Nef_polyhedron union operation.
> How can I ensure the faces near the joint are triangular?
>
> Thanks,
> Mengda
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
///////////////////////////////////////////////////////////////////////////
//
//
// Class: Enriched_polyhedron
//
//
//
///////////////////////////////////////////////////////////////////////////
#ifndef _POLYGON_MESH_
#define _POLYGON_MESH_
#include <CGAL/Cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <list>
// a refined facet with a normal
template <class Refs, class T, class P, class Norm>
class Enriched_facet : public CGAL::HalfedgeDS_face_base<Refs, T>
{
// normal
Norm m_normal;
public:
// life cycle
Enriched_facet()
{
}
// normal
typedef Norm Normal_3;
Normal_3& normal() { return m_normal; }
const Normal_3& normal() const { return m_normal; }
};
// a refined halfedge with a general tag
template <class Refs, class Tprev, class Tvertex, class Tface, class
Norm>
class Enriched_halfedge : public
CGAL::HalfedgeDS_halfedge_base<Refs,Tprev,Tvertex,Tface>
{
private:
// general-purpose tag
int m_tag;
public:
// life cycle
Enriched_halfedge()
{
}
// tag
int& tag() { return m_tag; }
const int& tag() const { return m_tag; }
void tag(const int& t) { m_tag = t; }
};
// a refined vertex with a normal and a tag
template <class Refs, class T, class P, class Norm>
class Enriched_vertex : public CGAL::HalfedgeDS_vertex_base<Refs,
T, P>
{
// normal
Norm m_normal;
public:
// life cycle
Enriched_vertex() {}
// repeat mandatory constructors
Enriched_vertex(const P& pt)
: CGAL::HalfedgeDS_vertex_base<Refs, T, P>(pt)
{
}
// normal
typedef Norm Normal_3;
Normal_3& normal() { return m_normal; }
const Normal_3& normal() const { return m_normal; }
};
// A redefined items class for the Polyhedron_3
// with a refined vertex class that contains a
// member for the normal vector and a refined
// facet with a normal vector instead of the
// plane equation (this is an alternative
// solution instead of using
// Polyhedron_traits_with_normals_3).
struct Enriched_items : public CGAL::Polyhedron_items_3
{
// wrap vertex
template <class Refs, class Traits>
struct Vertex_wrapper
{
typedef typename Traits::Point_3 Point;
typedef typename Traits::Vector_3
Normal;
typedef Enriched_vertex<Refs,
CGAL::Tag_true,
Point,
Normal> Vertex;
};
// wrap face
template <class Refs, class Traits>
struct Face_wrapper
{
typedef typename Traits::Point_3 Point;
typedef typename Traits::Vector_3
Normal;
typedef Enriched_facet<Refs,
CGAL::Tag_true,
Point,
Normal> Face;
};
// wrap halfedge
template <class Refs, class Traits>
struct Halfedge_wrapper
{
typedef typename Traits::Vector_3
Normal;
typedef Enriched_halfedge<Refs,
CGAL::Tag_true,
CGAL::Tag_true,
CGAL::Tag_true,
Normal> Halfedge;
};
};
// Enriched polyhedron
template <class kernel, class items>
class Enriched_polyhedron : public
CGAL::Polyhedron_3<kernel,items>
{
public :
typedef typename kernel::FT FT;
typedef typename kernel::Point_3 Point;
typedef typename kernel::Iso_cuboid_3 Iso_cuboid_3;
// range
Iso_cuboid_3 m_bounding_box;
public :
// life cycle
Enriched_polyhedron()
{
}
virtual ~Enriched_polyhedron()
{
}
void compute_range()
{
FT xmin,xmax,ymin,ymax,zmin,zmax;
xmin = ymin = zmin = 1e38;
xmax = ymax = zmax = -1e38;
for(Point_iterator it = points_begin();
it != points_end();
it++)
{
const Point& p = *it;
xmin = std::min(p.x(),xmin);
ymin = std::min(p.y(),ymin);
zmin = std::min(p.z(),zmin);
xmax = std::max(p.x(),xmax);
ymax = std::max(p.y(),ymax);
zmax = std::max(p.z(),zmax);
}
Point p(xmin,ymin,zmin);
Point q(xmax,ymax,zmax);
m_bounding_box = Iso_cuboid_3(p,q);
}
// tag all halfedges
void tag_halfedges(const int tag)
{
for(Halfedge_iterator pHalfedge = halfedges_begin();
pHalfedge != halfedges_end();
pHalfedge++)
pHalfedge->tag(tag);
}
// return max (width,height,depth) of the point set
FT size()
{
FT dx = m_bounding_box.xmax() - m_bounding_box.xmin();
FT dy = m_bounding_box.ymax() - m_bounding_box.ymin();
FT dz = m_bounding_box.zmax() - m_bounding_box.zmin();
return std::max(dx,std::max(dy,dz));
}
// return center of bounding box
Point center()
{
FT mx = 0.5 * (m_bounding_box.xmax() + m_bounding_box.xmin());
FT my = 0.5 * (m_bounding_box.ymax() + m_bounding_box.ymin());
FT mz = 0.5 * (m_bounding_box.zmax() + m_bounding_box.zmin());
return Point(mx,my,mz);
}
// normals (per facet, then per vertex)
void compute_normals_per_facet()
{
std::for_each(facets_begin(),facets_end(),Facet_normal());
}
void compute_normals_per_vertex()
{
std::for_each(vertices_begin(),vertices_end(),Vertex_normal());
}
void compute_normals()
{
compute_normals_per_facet();
compute_normals_per_vertex();
}
};
// compute facet normal
struct Facet_normal // (functor)
{
template <class Facet>
void operator()(Facet& f)
{
typename Facet::Normal_3 sum = CGAL::NULL_VECTOR;
typename Facet::Halfedge_around_facet_circulator h =
f.facet_begin();
do
{
typename Facet::Normal_3 normal =
CGAL::cross_product(
h->next()->vertex()->point() -
h->vertex()->point(),
h->next()->next()->vertex()->point() -
h->next()->vertex()->point());
double sqnorm = normal * normal;
if(sqnorm != 0)
normal = normal /
(float)std::sqrt(sqnorm);
sum = sum + normal;
}
while(++h != f.facet_begin());
double sqnorm = sum * sum;
if(sqnorm != 0.0)
f.normal() = sum / std::sqrt(sqnorm);
else
{
f.normal() = CGAL::NULL_VECTOR;
TRACE("degenerate face\n");
}
}
};
// compute vertex normal
struct Vertex_normal // (functor)
{
template <class Vertex>
void operator()(Vertex& v)
{
typename Vertex::Normal_3 normal =
CGAL::NULL_VECTOR;
Vertex::Halfedge_around_vertex_const_circulator pHalfedge =
v.vertex_begin();
Vertex::Halfedge_around_vertex_const_circulator begin = pHalfedge;
CGAL_For_all(pHalfedge,begin)
if(!pHalfedge->is_border())
normal = normal +
pHalfedge->facet()->normal();
double sqnorm = normal * normal;
if(sqnorm != 0.0f)
v.normal() = normal /
(float)std::sqrt(sqnorm);
else
v.normal() = CGAL::NULL_VECTOR;
}
};
#endif
- Nef_polyhedron: cannot convert to an enriched polyhedron, Mengda Wu, 04/07/2008
- Nef_polyhedron: cannot convert to an enriched polyhedron, Mengda Wu, 04/07/2008
- Message not available
- Re: Nef_polyhedron: cannot convert to an enriched polyhedron, Mengda Wu, 04/08/2008
- Re: [cgal-discuss] Re: Nef_polyhedron: cannot convert to an enriched polyhedron, Peter Hachenberger, 04/08/2008
- Re: [cgal-discuss] Re: Nef_polyhedron: cannot convert to an enriched polyhedron, Mengda Wu, 04/08/2008
- Re: [cgal-discuss] Re: Nef_polyhedron: cannot convert to an enriched polyhedron, Peter Hachenberger, 04/08/2008
- Re: Nef_polyhedron: cannot convert to an enriched polyhedron, Mengda Wu, 04/08/2008
- Message not available
- Nef_polyhedron: cannot convert to an enriched polyhedron, Mengda Wu, 04/07/2008
Archive powered by MHonArc 2.6.16.