CGAL::2D Arrangements-3

3.Arrangement查询

Arrangement里面最重要的查询操作是point-location,给定一个点,查找到包含这个点的Arrangement。通常情况下,point-location查询得到的结果是Arrangement的一个face,退化情况下会是一个edge,查一个重合的点。

3.1 point-Location查询
3.3 垂直射线扫描

另一个经常用到Arrangement的查找,是垂直射线扫描查找:给定一个查找点,哪些Arrangement单元会跟从这个点发射的垂直射线相交?一般情况下,可能这个射线交到一边edge,也有可能交到一个vertex,或者这个Arrangement单元不跟这个射线相交。

在前面章节讲到的point-location类,也是一个ArrangementVerticalRayShoot_2概念(concept)的一个model,所以他们全都有成员方法ray_shoot_up(q)和 ray_shoot_down(q),这其中的Q是一个用来查询的point。

在头文件point_location_utils.h中有下面的辅助方法:

template <typename VerticalRayShooting>
void shoot_vertical_ray(const RayShoot& vrs,
                        const typename
                        VerticalRayShooting::Arrangement_2::Point_2& q)
{
  typedef VerticalRayShooting                           Vertical_ray_shooting;
  // Perform the point-location query.
  typename Vertical_ray_shooting::result_type obj = vrs.ray_shoot_up(q);
  // Print the result.
  typedef typename Vertical_ray_shooting::Arrangement_2 Arrangement_2;
  typedef typename Arrangement_2::Vertex_const_handle   Vertex_const_handle;
  typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle;
  typedef typename Arrangement_2::Face_const_handle     Face_const_handle;
  const Vertex_const_handle* v;
  const Halfedge_const_handle* e;
  const Face_const_handle* f;
  std::cout << "Shooting up from (" << q << ") : ";
  if (v = boost::get<Vertex_const_handle>(&obj))         // we hit a vertex
    std::cout << "hit " << (((*v)->is_isolated()) ? "an isolated" : "a")
              << " vertex: " << (*v)->point() << std::endl;
  else if (e = boost::get<Halfedge_const_handle>(&obj))  // we hit an edge
    std::cout << "hit an edge: " << (*e)->curve() << std::endl;
  else if (f = boost::get<Face_const_handle>(&obj)) {    // we hit nothing
    CGAL_assertion((*f)->is_unbounded());
    std::cout << "hit nothing.\n";
  }
  else CGAL_error();
}

下面的程序段,使用了上面的函数模式,在一个Arrangement上执行垂直射线扫描查询:

// Answering vertical ray-shooting queries.
#include <CGAL/basic.h>
#include <CGAL/Arr_walk_along_line_point_location.h>
#include <CGAL/Arr_trapezoid_ric_point_location.h>
#include "arr_inexact_construction_segments.h"
#include "point_location_utils.h"
typedef CGAL::Arr_walk_along_line_point_location<Arrangement> Walk_pl;
typedef CGAL::Arr_trapezoid_ric_point_location<Arrangement>   Trap_pl;
int main() {
  // Construct the arrangement.
  Arrangement arr;
  construct_segments_arr(arr);
  // Perform some vertical ray-shooting queries using the walk strategy.
  Walk_pl walk_pl(arr);
  shoot_vertical_ray(walk_pl, Point(1, 4));
  shoot_vertical_ray(walk_pl, Point(4, 3));
  shoot_vertical_ray(walk_pl, Point(6, 3));
  // Attach the trapezoid-RIC object to the arrangement and perform queries.
  Trap_pl trap_pl(arr);
  shoot_vertical_ray(trap_pl, Point(3, 2));
  shoot_vertical_ray(trap_pl, Point(5, 2));
  shoot_vertical_ray(trap_pl, Point(1, 0));
  return 0;
}

相关推荐

  1. CGAL::2D Arrangements-3

    2024-02-07 06:24:03       50 阅读
  2. CGAL::2D Arrangements-2

    2024-02-07 06:24:03       54 阅读
  3. CGAL::2D Arrangements-8

    2024-02-07 06:24:03       57 阅读
  4. CGAL::2D Arrangements-5

    2024-02-07 06:24:03       52 阅读
  5. CGAL::2D Arrangements-4

    2024-02-07 06:24:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-07 06:24:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-07 06:24:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-07 06:24:03       82 阅读
  4. Python语言-面向对象

    2024-02-07 06:24:03       91 阅读

热门阅读

  1. 使用lodash防抖节流

    2024-02-07 06:24:03       51 阅读
  2. Spark scala如何本地运行

    2024-02-07 06:24:03       48 阅读
  3. leetcode - 408. Valid Word Abbreviation

    2024-02-07 06:24:03       40 阅读
  4. Docker- chapter 1

    2024-02-07 06:24:03       47 阅读
  5. 谈谈mybatis的理解(一)

    2024-02-07 06:24:03       52 阅读
  6. 小程序API开发——文件FileSystemManager参数汇总

    2024-02-07 06:24:03       44 阅读
  7. 深度解析与推荐:主流Web前端开发框架

    2024-02-07 06:24:03       47 阅读
  8. Lua函数进阶

    2024-02-07 06:24:03       56 阅读
  9. LCP 30. 魔塔游戏---leetcode

    2024-02-07 06:24:03       54 阅读
  10. 嵌入式linux驱动开发之网络设备驱动

    2024-02-07 06:24:03       45 阅读
  11. 前端下载文件有哪些方式

    2024-02-07 06:24:03       53 阅读
  12. day12笔记(学生管理系统升级版)

    2024-02-07 06:24:03       47 阅读