Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Custom Polyhedron_3 and Polyhedron_incremental_builder_3 problems

Subject: CGAL users discussion list

List archive

[cgal-discuss] Custom Polyhedron_3 and Polyhedron_incremental_builder_3 problems


Chronological Thread 
  • From: Vicomt <>
  • To:
  • Subject: [cgal-discuss] Custom Polyhedron_3 and Polyhedron_incremental_builder_3 problems
  • Date: Thu, 7 Jan 2010 07:05:30 -0800 (PST)


Hi all, a new user here, not so well versed in using C++ templates, so I'm
having some trouble.

I'm using a custom Polyhedron_3 in the form:

typedef CGAL::Exact_predicates_exact_constructions_kernel MY_Kernel;
typedef MY_Traits < MY_Kernel > MY_PolyhedronTraits;
typedef MY_Items MY_PolyhedronItems;
typedef CGAL::Polyhedron_3 <MY_PolyhedronTraits, MY_PolyhedronItems>
MY_Polyhedron;
typedef MY_Polyhedron::HalfedgeDS HalfedgeDS;


The MY_Traits class is defined:

template < class Kernel_ >
class MY_Traits {
public:
typedef Kernel_ Kernel;
typedef typename Kernel::Point_3 Point_3;
typedef typename Kernel::Vector_3 Vector_3;
typedef typename Kernel::Plane_3 Plane_3;

typedef typename Kernel::Construct_opposite_vector_3
Construct_opposite_vector_3;
private:
Kernel m_kernel;

public:
MY_Traits() {}
MY_Traits( const Kernel& kernel)
: m_kernel(kernel) {}

Construct_opposite_vector_3 construct_opposite_vector_3_object()
const {
return m_kernel.construct_opposite_vector_3_object();
}
};

with Facet_normal, Vertex_normal, and Halfedge_normal functors.


the MY_Items class is defined:

struct MY_Items : public CGAL::Polyhedron_items_3 {
template <class Refs, class Traits> struct Vertex_wrapper
{
typedef typename Traits::Point_3 Point;
typedef typename Traits::Vector_3 Normal;
typedef MY_Mesh_Vertex<Refs, CGAL::Tag_true, Point, Normal>
Vertex;
};
template <class Refs, class Traits> struct Face_wrapper
{
typedef typename Traits::Vector_3 Normal;
typedef MY_Mesh_Facet<Refs, CGAL::Tag_true, Normal> Face;
};
template <class Refs, class Traits> struct Halfedge_wrapper
{
typedef typename Traits::Vector_3 Normal;
typedef typename unsigned short EdgeType;
typedef MY_Mesh_Halfedge<Refs, CGAL::Tag_true, CGAL::Tag_true,
CGAL::Tag_true, Normal, EdgeType> Halfedge;
};
};

with associated vertex, face and halfedge wrappers:

template <class Refs, class T, class P, class Norm>
class MY_Mesh_Vertex : public CGAL::HalfedgeDS_vertex_base<Refs, T, P> {
Norm norm;
public:
MY_Mesh_Vertex() {} // repeat mandatory constructors
MY_Mesh_Vertex( const P& pt) : CGAL::HalfedgeDS_vertex_base<Refs, T,
P>(pt)
{}
typedef Norm Normal_3;
Normal_3& normal() { return norm; }
const Normal_3& normal() const { return norm; }
};

template <class Refs, class T, class Norm>
class MY_Mesh_Facet : public CGAL::HalfedgeDS_face_base<Refs, T> {
Norm norm;
public:
// no constructors to repeat, since only default constructor mandatory
typedef Norm Normal_3;
Normal_3& normal() { return norm; }
const Normal_3& normal() const { return norm; }
};

template <class Refs, class P, class V, class F, class Norm, class Tag>
class MY_Mesh_Halfedge : public CGAL::HalfedgeDS_halfedge_base<Refs, P, V,
F> {
Norm m_norm;
Tag m_tag;
public:
typedef Norm Normal_3;
Normal_3& normal() { return m_norm; }
const Normal_3& normal() const { return m_norm; }

Tag& tag() { return m_tag; }
const Tag& tag() const { return m_tag; }
};


the intention of all this is to give me a halfedge data structure, with
added normals at vertices, faces and halfedges, and an extra "tag" on the
halfedge that I can use to store application specified edge types.

However, when I come to use a Polyhedron_incremental_builder_3 derived class
to allow me to add faces (or in this particular case, holes to faces), I
can't get it to compile. My incremental builder is defined as follows:

template <class HDS>
class HoleBuilder : public CGAL::Modifier_base<HDS> {
public:
HoleBuilder() {gHoleBuilder_HolePointsArray.removeAll();
gHoleBuilder_HoleTagsArray.removeAll();}
void operator()(HDS &hds)
{
CGAL::Polyhedron_incremental_builder_3<HDS> polyBuilder( hds,
true);
long iNumVertices=0;
for(long
iFaceIndex=0;iFaceIndex<gHoleBuilder_HolePointsArray.logicalLength();iFaceIndex++)

iNumVertices+=gHoleBuilder_HolePointsArray[iFaceIndex].logicalLength();

polyBuilder.begin_surface( iNumVertices,
gHoleBuilder_HolePointsArray.logicalLength());

for(long
iFaceIndex=0;iFaceIndex<gHoleBuilder_HolePointsArray.logicalLength();iFaceIndex++)
{
Point3dArray p3aFaceVertices =
gHoleBuilder_HolePointsArray[iFaceIndex];
for(long i=0;i<p3aFaceVertices.logicalLength();i++)
{
Point3d p3Vertex = p3aFaceVertices[i];
typedef HDS::Vertex Vertex;
typedef Vertex::Point Point;
polyBuilder.add_vertex( Point( p3Vertex.x,
p3Vertex.y, p3Vertex.z));
}
polyBuilder.begin_facet();
for(long i=0;i<p3aFaceVertices.logicalLength();i++)
{
polyBuilder.add_vertex_to_facet(i);
}
typedef HDS::Halfedge_handle Halfedge_handle;
Halfedge_handle ehStartEdge = polyBuilder.end_facet();
Halfedge_handle ehEdge = ehStartEdge;
long iEdgeTagIndex=0;
do {

ehEdge->tag()=gHoleBuilder_HoleTagsArray[iFaceIndex][iEdgeTagIndex];

ehEdge->opposite()->tag()=gHoleBuilder_HoleTagsArray[iFaceIndex][iEdgeTagIndex];
ehEdge = ehEdge->next();
iEdgeTagIndex++;
} while(ehEdge != ehStartEdge);
hds.make_hole(ehStartEdge);
}

polyBuilder.end_surface();
}
void addHole(const Point3dArray &p3aFaceVertices, const
UnsignedShortArray
&crui16aEdgeTags)
{
gHoleBuilder_HolePointsArray.append(p3aFaceVertices);
gHoleBuilder_HoleTagsArray.append(crui16aEdgeTags);
}
};

and is used in the form:

HoleBuilder <MY_Polyhedron> hbHole;
hbHole.addHole(VertexArray1, EdgeTagArray1);
hbHole.addHole(VertexArray2, EdgeTagArray2);
...
hbHole.addHole(VertexArrayN, EdgeTagArrayN);
m_Mesh.delegate(hbHole);

this should allow me to batch add faces which are holes. this is the part
that won't compile, I get the following error:

1>my_mesh.cpp(397) : error C2664:
'CGAL::Polyhedron_3<PolyhedronTraits_3,PolyhedronItems_3>::delegate' :
cannot convert parameter 1 from 'HoleBuilder<HDS>' to
'CGAL::Modifier_base<R> &'
1> with
1> [
1> PolyhedronTraits_3=MY_Mesh::MY_PolyhedronTraits,
1> PolyhedronItems_3=MY_Mesh::MY_PolyhedronItems
1> ]
1> and
1> [
1> HDS=MY_Mesh::MY_Polyhedron
1> ]
1> and
1> [
1>
R=CGAL::HalfedgeDS_default<MY_Traits<MY_Mesh::MY_Kernel>,CGAL::I_Polyhedron_derived_items_3<MY_Items>,std::allocator<int>>
1> ]

and I can't understand why it can't convert from my HoleBuilder class to its
CGAL base class.

I can get rid of this however, by using the HalfedgeDS definition (typedef
MY_Polyhedron::HalfedgeDS HalfedgeDS;) like so:

HoleBuilder <HalfedgeDS> hbHole;
hbHole.addHole(VertexArray1, EdgeTagArray1);
hbHole.addHole(VertexArray2, EdgeTagArray2);
...
hbHole.addHole(VertexArrayN, EdgeTagArrayN);
m_Mesh.delegate(hbHole);

but this then leave me with the following compile error:

1>error C2039: 'make_hole' : is not a member of
CGAL::HalfedgeDS_default<Traits_,HalfedgeDSItems,Alloc>'

which I can understand, as its a method of Polyhedron_3, not HalfedgeDS, so
that might be a red herring, but it's what I've seen in the all the
available documentation, so I thought I'd try it.

So anyway, that's where I am, and I don't understand what I'm doing wrong.
Any ideas?

Karl

--
View this message in context:
http://n4.nabble.com/Custom-Polyhedron-3-and-Polyhedron-incremental-builder-3-problems-tp1008880p1008880.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.16.

Top of Page