a48
2.0.2
|
This is an example of how to use the Items Policy paradigm using the a48 halfedge datastructure classes.
#include <mesh.hh> #include <cstring> template< class Traits > class MyVertex : public a48::VertexT< Traits > { public: unsigned int id; float pos[2]; }; template< class Traits > class MyHalfedge : public a48::HalfedgeT< Traits > { public: float thickness; }; template< class Traits > class MyFace : public a48::FaceT< Traits > { public: float color[3]; }; class MyTraits { public: typedef MyVertex< MyTraits > vertex_type; typedef MyHalfedge< MyTraits > halfedge_type; typedef MyFace< MyTraits > face_type; }; typedef a48::MeshT< MyTraits > MyMesh; template< class Traits > class MyItemsPolicy : public virtual a48::BaseItemsPolicy< Traits > { typedef typename Traits::vertex_type vertex_type; typedef typename Traits::halfedge_type halfedge_type; typedef typename Traits::face_type face_type; public: unsigned int num_verts, num_faces; float *vertices; unsigned int *faces; float *edge_thickness; float *face_colors; MyItemsPolicy() { num_verts = 3; num_faces = 1; const float _vertices[] = { 0.f, 0.f, 1.f, 0.f, 1.f, 1.f }; const unsigned int _faces[] = { 0, 1, 2 }; vertices = new float[ num_verts * 2 ]; faces = new unsigned int[ num_faces * 3 ]; edge_thickness = new float[ 3 ]; edge_thickness[0] = .1f; edge_thickness[1] = .2f; edge_thickness[2] = .3f; face_colors = new float[ 3 ]; face_colors[0] = .8f; face_colors[1] = .2f; face_colors[2] = .2f; memcpy( vertices, _vertices, num_verts * 2 * sizeof(float) ); memcpy( faces, _faces, num_faces * 3 * sizeof(unsigned int) ); } ~MyItemsPolicy() { delete [] vertices; delete [] faces; delete [] edge_thickness; delete [] face_colors; } void set_vertex_attributes(vertex_type *v1, const vertex_type *v0) { v1->id = v0->id; v1->pos[0] = v0->pos[0]; v1->pos[1] = v0->pos[1]; } void set_vertex_attributes(const unsigned int& i, vertex_type *v) { v->id = i; v->pos[0] = vertices[ i*2 + 0 ]; v->pos[1] = vertices[ i*2 + 1 ]; } void set_halfedge_attributes(halfedge_type *h1, const halfedge_type *h0) { h1->thickness = h0->thickness; } void set_halfedge_attributes(halfedge_type *h, halfedge_type *o) { o->thickness -= .05f; h->thickness = o->thickness; } void set_halfedge_attributes(const unsigned int& i, const unsigned int& j, const unsigned int& hi, halfedge_type *h) { h->thickness = edge_thickness[ i+j - 1 ]; } void set_face_attributes(face_type *f1, const face_type *f0) { f1->color[0] = f0->color[0]; f1->color[1] = f0->color[1]; f1->color[2] = f0->color[2]; } void set_face_attributes(const unsigned int& i, face_type *f) { f->color[0] = face_colors[ i*3 + 0 ]; f->color[1] = face_colors[ i*3 + 1 ]; f->color[2] = face_colors[ i*3 + 2 ]; } }; void example(void) { MyItemsPolicy< MyTraits > ip; MyMesh m( &ip ); m.set_base( ip.num_verts, ip.num_faces, ip.faces ); }