CGAL 2维布尔运算

研究了几天nef_2,终于明白了一点,写下来记录一下

本文主要讨论nef布尔运算后Explorer的情况

#include <CGAL/Gmpq.h>
#include <CGAL/Lazy_exact_nt.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Bounded_kernel.h>
#include <CGAL/Nef_polyhedron_2.h>


typedef CGAL::Lazy_exact_nt<CGAL::Gmpq> FT;
typedef CGAL::Simple_cartesian<FT> Kernel;
typedef CGAL::Bounded_kernel<Kernel> Extended_kernel;
typedef CGAL::Nef_polyhedron_2<Extended_kernel> Nef_polyhedron;
typedef Nef_polyhedron::Point Point;

typedef Nef_polyhedron::Explorer Explorer;
typedef Explorer::Face_const_iterator Face_const_iterator;
typedef Explorer::Hole_const_iterator Hole_const_iterator;
typedef Explorer::Halfedge_around_face_const_circulator Halfedge_around_face_const_circulator;
typedef Explorer::Vertex_const_handle Vertex_const_handle;
typedef Explorer::Point_const_iterator Point_const_iterator;
typedef Explorer::Isolated_vertex_const_iterator Isolated_vertex_const_iterator;

头文件和预定义,没什么好说的,下面开始三角形和线段的定义

    Point r1[3] = { Point(20, 15), Point(25, 5), Point(30, 15) };
  Point s0[2] = { Point(20, 10), Point(25, 16) };

    Nef_polyhedron RST0(r1, r1 + 3, Nef_polyhedron::INCLUDED);
    Nef_polyhedron RST1(s0, s0 + 2, Nef_polyhedron::INCLUDED);
 

 /*   std::list<std::pair<Point*, Point*> > polylines, polylines1;
    polylines.push_back(std::make_pair(r1 + 0, r1 + 3));
    polylines1.push_back(std::make_pair(s0 + 0, s0 + 2));

  Nef_polyhedron RST0(polylines.begin(), polylines.end(), Nef_polyhedron::POLYGONS);//定义多边形
    Nef_polyhedron RST1(polylines1.begin(), polylines1.end(), Nef_polyhedron::POLYLINES);//多段线

*/

//相交运算

    Nef_polyhedron RST = RST1.intersection(RST0);

//使用探测器

Explorer explorer = RST.explorer();

//遍历点

std::cout << "Point" << std::endl;
    for (Point_const_iterator pntPos = explorer.points_begin(); pntPos != explorer.points_end(); ++pntPos)
    {
        std::cout << pntPos->x() << "," << pntPos->y() << std::endl;
    }

//半边

std::cout << "halfedges" << std::endl;
    for (Explorer::Halfedge_const_iterator posEdge = explorer.halfedges_begin(); posEdge != explorer.halfedges_end(); ++posEdge)
    {
        Vertex_const_handle vh = explorer.target(posEdge);
        std::cout << explorer.point(vh) << " [" << explorer.point(vh).x() << " | " << explorer.point(vh).y() << "],  ";
    }

//开始面的遍历

//第一个面是无限大的面,没有外轮廓,只包含洞

Face_const_iterator posFace = explorer.faces_begin();
    for (Hole_const_iterator hit = explorer.holes_begin(posFace); hit != explorer.holes_end(posFace); hit++)
    {
        std::cout << " A hole" << std::endl;

//半边循环
        Halfedge_around_face_const_circulator hafc(hit), done(hafc);
        do
        {
            Vertex_const_handle vh = explorer.target(hafc);
            std::cout << explorer.point(vh) << " [" << explorer.point(vh).x() << " | " << explorer.point(vh).y() << "],  ";
            hafc++;
        } while (hafc != done);
    }

//其他面,有外轮廓,包含洞

for (++posFace; posFace != explorer.faces_end(); ++posFace)
    {
        
        Halfedge_around_face_const_circulator hafc = explorer.face_cycle(posFace), done(hafc);
        do
        {
            Vertex_const_handle vh = explorer.target(hafc);
            std::cout << explorer.point(vh) << " [" << explorer.point(vh).x()<< " | " << explorer.point(vh).y() << "],  ";
            hafc++;
        } while (hafc != done);
    }

 //注明一下,当使用布尔运算时.需要保证2个多边形转向相同,否则相交运算变成合并运算, 合并运算变相交运算

 

转载于:https://www.cnblogs.com/zm147451753/p/4233336.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值