码迷,mamicode.com
首页 > 其他好文 > 详细

使用CGAL查找输入三角网格模型独立模型个数

时间:2014-12-17 20:12:38      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   使用   sp   for   on   文件   

在对三角网格模型进行切分并且对切分模型三角化之后,可能会遇到分块数 > 2的情况,对于这种情况我们就需要得到各个分块的数量,并且将他们重组成独立的三角网格模型。

思路如下:

建立一个存放三角网格面的堆栈,遍历模型的所有的三角网格面,对每一个三角形都搜索与之相邻的三个三角形(每个边对应一个三角形),将这些三角形放入堆栈,直到堆栈为空表明已经找到属于同一个块的三角网格。再遍历以上过程,直到所有的三角网格都有属于自己的块。

在CGAL的Polyhedron_3.h头文件的Facet类里加入一个int型标志位mask,并且在构造器里将其初始化为0。接下来是具体的搜索过程,trilist是一个Facet_handle类型的堆栈。

    int noc = 0;
    Facet_handle t , s;
    
    //所有的facet的mask都为0
    for(Facet_iterator it = P1.facets_begin() , end = P1.facets_end() ;
        it != end;it++)
    {
        if(!it->mask)
        {
            noc ++ ;
            trilist.push(it);
            it->mask = noc ;
            while(trilist.size())
            {
                t = trilist.top();
                trilist.pop();
                if((s=t->halfedge()->opposite()->facet()) != NULL && (!s->mask)) {trilist.push(s);s->mask=noc;}
                if((s=t->halfedge()->next()->opposite()->facet()) != NULL && (!s->mask)){trilist.push(s);s->mask=noc;}
                if((s=t->halfedge()->prev()->opposite()->facet()) != NULL && (!s->mask)){trilist.push(s);s->mask=noc;} 
            }
        }
        //std::cout << "Mask of facet is "<< it->mask <<std::endl;
    } 
    std::cout << "Number of components is "<< noc <<std::endl;

 

使用CGAL查找输入三角网格模型独立模型个数

标签:style   blog   color   os   使用   sp   for   on   文件   

原文地址:http://www.cnblogs.com/jast/p/4169977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!