mesh 转化为CGAL_Polyhedron_3

Hi Zohar, thank you very much for the reply!

 

This will indeed give me a lot to chew on in the future.

 

The mesh I’m using is the 3DS Max 2009 SDK mesh class.  The Max mesh object is a similar half-edge based data structure to Polyhedron_3.

 

I have successfully written functions for converting a mesh object to an array of CGAL Point_3 values to pass to various functions, what I am stuck on however is converting a Polyhedron_3 back to a 3DS Max mesh object.   The mesh object stores it’s vertices and faces (tri facets) as arrays.  Now each face is described as 3 indices into the vertex array.  So to create a new face in the mesh object I need to know the indices into the vertex array of the vertices it uses.  This is the bit I’m stuck on using Polyhedron_3.  Do I need to cast the Polyhedron_3 into a HalfEdge_DS of some sort to access this data?

 

PS: What is the SRC from that you posted?  I’m planning on releasing the SRC I’m working on with a generic pack of utils for 3DS Max.

 

 

From: Zohar Levi [mailto: [email protected] ]
Sent: Monday, 31 August 2009 7:50 PM
To: [email protected]
Subject: [cgal-discuss] RE: Iterating over Polyhedron facets

 


An example converting Maya mesh (which one do you use?) to CGAL Polyhedron:

template <class Refs>
struct My_face : public CGAL::HalfedgeDS_face_base<Refs> {
    unsigned id;
};

template <class Refs, class Point>
struct My_vertex : public CGAL::HalfedgeDS_vertex_base<Refs, CGAL::Tag_true, Point> {
    My_vertex() {}
    My_vertex(const Point& pt) : CGAL::HalfedgeDS_vertex_base<Refs, CGAL::Tag_true, Point>(pt) {}
    unsigned id;
};

// An items type using my face and vertex.
struct My_items : public CGAL::Polyhedron_items_3 {
    template <class Refs, class Traits>
    struct Face_wrapper {
        typedef My_face<Refs> Face;
    };

    template <class Refs, class Traits>
    struct Vertex_wrapper {
        typedef typename Traits::Point_3 Point;
        typedef My_vertex<Refs, Point> Vertex;
    };

};

typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel, My_items> Polyhedron;


// A modifier converting a Maya mesh to CGAL Polyhedron_3
template <class HDS>
class Mesh_to_polyhedron : public CGAL::Modifier_base<HDS> {
public:
    Mesh_to_polyhedron(MFnMesh &mesh) : m_mesh(mesh.object()) {}
    void operator()(HDS& hds) {
        // get mesh data
        MFloatPointArray pts;
        m_mesh.getPoints(pts);
        MIntArray tcounts, tvers;
        m_mesh.getTriangles(tcounts, tvers);

        // Postcondition: `hds' is a valid polyhedral surface.
        CGAL::Polyhedron_incremental_builder_3<HDS> B(hds, true);
        B.begin_surface(pts.length(), tvers.length()/3);
        // vertices
        typedef typename HDS::Vertex::Point Vertex;
        typedef typename Vertex Point;
        for ( unsigned i = 0 ; i < pts.length() ; i++ ) {
            HDS::Vertex_handle vh = B.add_vertex(Point(pts[i].x,pts[i].y,pts[i].z));
            vh->id = i;
        }

        // triangles
        for ( unsigned i = 0 ; i < tvers.length()/3 ; i++ ) {
            HDS::Face_handle fh = B.begin_facet();
            B.add_vertex_to_facet(tvers[3*i]);
            B.add_vertex_to_facet(tvers[3*i+1]);
            B.add_vertex_to_facet(tvers[3*i+2]);
            B.end_facet();
            fh->id = i;
        }

        B.end_surface();
    }

private:
    MFnMesh m_mesh;
};

void mesh2polyhedron(MFnMesh &mesh, Polyhedron &P)
{
    Mesh_to_polyhedron<Polyhedron::HalfedgeDS> builder(mesh);
    P.delegate(builder);
}

你可能感兴趣的:(struct,object,Class,facet,wrapper,structure)