mesh 转化为CGAL_Polyhedron_3

 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);
}

 

摘自: http://blog.csdn.net/csmqq/article/details/5312578

http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Polyhedron_ref/Class_Polyhedron_incremental_builder_3.html#Cross_link_anchor_697

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值