Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >CGAL:带信息点的凸包

CGAL:带信息点的凸包
EN

Stack Overflow用户
提问于 2017-04-28 06:40:02
回答 1查看 442关注 0票数 2

我在平面上有一个二维点(N元素)的向量。我想做这些点的凸包。在此之后,我要检索凸壳中每个顶点的向量索引,我如何做到这一点?

我知道,利用vector<pair<Point_2, unsigned> >进行三角剖分是有可能的,但是当我用配对点制作凸包时,它会产生大量的误差。这是我使用的相关代码:

代码语言:javascript
运行
AI代码解释
复制
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
#include <CGAL/convex_hull_traits_2.h>

using namespace std;

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef pair<Point_2, unsigned> Paired;
typedef CGAL::convex_hull_traits_2<Paired> ch_traits;

typedef vector<Paired> Vector;

int main()
{
    Vector points;
    Vector result;

    for (int i = 0; i < 5; i++)
         points.push_back(make_pair(Point_2(i, i), i));
    CGAL::convex_hull_2( points.begin(), points.end(), back_inserter(result), const Traits &ch_traits );

  return 0;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-01 23:16:19

您需要提供一个ConvexHullTraits的特性类模型,对类型是您的点类型。在实践中,它非常简单,您只需要一个包含所有函子的结构,而运算符只需使用pair::first将运算符转发到CGAL类函子。

下面是一个简单的例子:

代码语言:javascript
运行
AI代码解释
复制
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
#include <CGAL/convex_hull_traits_2.h>

#include <boost/foreach.hpp>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef std::pair<Point_2, unsigned> Point_with_info;

template <class F>
struct Forward_functor
  : public F
{
  template <class Point_2>
  bool operator() (const Point_2& p, const Point_2& q) const
  {
    return static_cast<const F*>(this)->operator()(p.first, q.first);
  }

  template <class Point_2>
  bool operator() (const Point_2& p, const Point_2& q, const Point_2& r) const
  {
    return static_cast<const F*>(this)->operator()(p.first, q.first, r.first);
  }

  template <class Point_2>
  bool operator() (const Point_2& p, const Point_2& q, const Point_2& r, const Point_2& s) const
  {
    return static_cast<const F*>(this)->operator()(p.first, q.first, r.first, s.first);
  }
};

struct CH_traits_for_point_with_info
{
  typedef Point_with_info Point_2;
  typedef CGAL::Convex_hull_traits_2<K> Base;
  typedef Forward_functor<Base::Less_xy_2> Less_xy_2;
  typedef Forward_functor<Base::Less_yx_2> Less_yx_2;
  typedef Forward_functor<Base::Less_signed_distance_to_line_2> Less_signed_distance_to_line_2;
  typedef Forward_functor<Base::Less_rotate_ccw_2> Less_rotate_ccw_2;
  typedef Forward_functor<Base::Left_turn_2> Left_turn_2;
  typedef Forward_functor<Base::Equal_2> Equal_2;

  struct Orientation_2
  {
    CGAL::Orientation
    operator()(const Point_2& p, const Point_2& q, const Point_2& r) const
    {
      return Base::Orientation_2()(p.first, q.first, r.first);
    }
  };

  Equal_2 equal_2_object () const
  {
    return Equal_2();
  }

  Less_xy_2 less_xy_2_object () const
  {
    return Less_xy_2();
  }

  Less_yx_2 less_yx_2_object () const
  {
    return Less_yx_2();
  }

  Less_signed_distance_to_line_2 less_signed_distance_to_line_2_object () const
  {
    return Less_signed_distance_to_line_2();
  }

  Less_rotate_ccw_2 less_rotate_ccw_2_object () const
  {
    return Less_rotate_ccw_2();
  }

  Left_turn_2 left_turn_2_object () const
  {
    return Left_turn_2();
  }

  Orientation_2 orientation_2_object () const
  {
    return Orientation_2();
  }
};

int main()
{
  std::vector<Point_with_info> input_points;
  std::vector<Point_with_info> result;

  input_points.push_back( Point_with_info(Point_2(0,0), 0) );
  input_points.push_back( Point_with_info(Point_2(1,0), 1) );
  input_points.push_back( Point_with_info(Point_2(0,1), 2) );
  input_points.push_back( Point_with_info(Point_2(0.25,0.25), 3) );

  CGAL::convex_hull_2(input_points.begin(), input_points.end(),
                      back_inserter(result), CH_traits_for_point_with_info() );

  BOOST_FOREACH(const Point_with_info& p, result)
  {
    std::cout << p.first << " - " << p.second << "\n";
  }

  return 0;
}

下面是一个更复杂的例子,在这个例子中,点没有被复制,而且算法正在处理点索引:

代码语言:javascript
运行
AI代码解释
复制
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
#include <CGAL/convex_hull_traits_2.h>

#include <boost/foreach.hpp>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;


template <class F>
struct Forward_functor
  : public F
{
  const std::vector<Point_2>& points;

  Forward_functor(const std::vector<Point_2>& points)
    : points(points)
  {}

  template <class Id>
  bool operator() (const Id& p, const Id& q) const
  {
    return static_cast<const F*>(this)->operator()(points[p], points[q]);
  }

  template <class Id>
  bool operator() (const Id& p, const Id& q, const Id& r) const
  {
    return static_cast<const F*>(this)->operator()(points[p], points[q], points[r]);
  }

  template <class Id>
  bool operator() (const Id& p, const Id& q, const Id& r, const Id& s) const
  {
    return static_cast<const F*>(this)->operator()(points[p], points[q], points[r], points[s]);
  }
};

struct CH_traits_for_point_with_info
{
  const std::vector<K::Point_2>& points;

  CH_traits_for_point_with_info(const std::vector<K::Point_2>& points)
    : points(points)
  {}

  typedef unsigned Point_2;
  typedef CGAL::Convex_hull_traits_2<K> Base;
  typedef Forward_functor<Base::Less_xy_2> Less_xy_2;
  typedef Forward_functor<Base::Less_yx_2> Less_yx_2;
  typedef Forward_functor<Base::Less_signed_distance_to_line_2> Less_signed_distance_to_line_2;
  typedef Forward_functor<Base::Less_rotate_ccw_2> Less_rotate_ccw_2;
  typedef Forward_functor<Base::Left_turn_2> Left_turn_2;
  typedef Forward_functor<Base::Equal_2> Equal_2;

  struct Orientation_2
  {
    const std::vector<K::Point_2>& points;

    Orientation_2(const std::vector<K::Point_2>& points)
      : points(points)
    {}

    CGAL::Orientation
    operator()(Point_2 p, Point_2 q, Point_2 r) const
    {
      return Base::Orientation_2()(points[p], points[q], points[r]);
    }
  };

  Equal_2 equal_2_object () const
  {
    return Equal_2(points);
  }

  Less_xy_2 less_xy_2_object () const
  {
    return Less_xy_2(points);
  }

  Less_yx_2 less_yx_2_object () const
  {
    return Less_yx_2(points);
  }

  Less_signed_distance_to_line_2 less_signed_distance_to_line_2_object () const
  {
    return Less_signed_distance_to_line_2(points);
  }

  Less_rotate_ccw_2 less_rotate_ccw_2_object () const
  {
    return Less_rotate_ccw_2(points);
  }

  Left_turn_2 left_turn_2_object () const
  {
    return Left_turn_2(points);
  }

  Orientation_2 orientation_2_object () const
  {
    return Orientation_2(points);
  }
};

int main()
{
  std::vector<Point_2> input_points;
  std::vector<unsigned> ids;
  std::vector<unsigned> result;

  input_points.push_back( Point_2(0,0) );
  input_points.push_back( Point_2(0,1) );
  input_points.push_back( Point_2(1,0) );
  input_points.push_back( Point_2(0.25,0.25) );

  ids.push_back(0);
  ids.push_back(1);
  ids.push_back(2);
  ids.push_back(3);

  CGAL::convex_hull_2(ids.begin(), ids.end(),
                      back_inserter(result), CH_traits_for_point_with_info(input_points) );

  BOOST_FOREACH(unsigned i, result)
  {
    std::cout << input_points[i] << " - " << i << "\n";
  }

  return 0;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43682852

复制
相关文章
基于图像分类的动态图像增强
论文链接:http://openaccess.thecvf.com/content_cvpr_2018/papers/Sharma_Classification-Driven_Dynamic_Image_CVPR_2018_paper.pdf
Natalia_ljq
2020/06/03
1.5K0
基于图像分类的动态图像增强
图像加雾仿真
算法:图像加雾仿真是降低亮度、对比度、和分辨率来模拟雾中场景成像接近真实雾霾场景。
裴来凡
2022/05/29
8770
图像加雾仿真
OpenCV中如何读取URL图像文件
最近知识星球收到的提问,觉得是一个很有趣的问题,就通过搜集整理归纳了一番,主要思想是通过URL解析来生成数据,转为图像/Mat对象。但是在Python语言与C++语言中的做法稍有不同。
OpenCV学堂
2019/07/19
5.9K0
在Swift中创建可缩放的图像视图
没有什么比完美的图片更能让你的应用程序熠熠生辉,但如果你想让你的应用程序用户真正参与并与图片互动呢?也许他们想放大、平移、掌握这些图像?
玖柒的小窝
2021/11/05
5.8K0
图像动态融合
算法:图像动态融合是以第一张图为主图,保留主图部分颜色信息和边缘信息,以第二张图为融入源,保留融入源部分颜色信息,动态调整融入比例。
裴来凡
2022/05/29
3810
图像动态融合
Halcon 创建图像
Halcon 中 HImage 为图像的数据结构,本文记录 HALCON 中生成图像的几种方式。 创建图像相关算子 序号 算子名称 算子含义 1 copy_image 复制一个图像并为其分配新的内存。 2 gen_image1 从指向像素的指针创建图像。 3 gen_image1_extern 使用存储管理从像素上的指针创建图像。 4 gen_image1_rect 从像素上的指针创建一个带有矩形域的图像(带存储管理)。 5 gen_image3 创建一个从三个指针到像素(红色/绿色/蓝色)的图像。
为为为什么
2023/02/18
3.6K0
Halcon 创建图像
如何将SVG图像使用在HTML网站中
使用PS生成SVG图像用编辑器打开发现是data:img/png;base64而非/path
Din
2018/10/19
4.8K0
如何将SVG图像使用在HTML网站中
图像中的几何变换
一. 图像几何变换概述 图像几何变换是指用数学建模的方法来描述图像位置、大小、形状等变化的方法。在实际场景拍摄到的一幅图像,如果画面过大或过小,都需要进行缩小或放大。如果拍摄时景物与摄像头不成相互平行关系的时候,会发生一些几何畸变,例如会把一个正方形拍摄成一个梯形等。这就需要进行一定的畸变校正。在进行目标物的匹配时,需要对图像进行旋转、平移等处理。在进行三维景物显示时,需要进行三维到二维平面的投影建模。因此,图像几何变换是图像处理及分析的基础。 二. 几何变换基础 1. 齐次坐标: 齐次坐标表示是计算机图形
智能算法
2018/04/02
2.2K0
图像中的几何变换
图像中的裂纹检测
我们首先需要从互联网上获取包含墙壁裂缝的图像(URL格式)数据。总共包含1428张图像:其中一半是新的且未损坏的墙壁;其余部分显示了各种尺寸和类型的裂缝。
小白学视觉
2021/01/18
1.4K0
Taro中如何将store加载到项目中
上面文章我们了解了如何创建store,最后导出时,在函数内部创建了store,所以导出时,函数需要调用,然后通过provicer组件将其注入到项目中。
挥刀北上
2022/05/11
7780
Taro中如何将store加载到项目中
【短道速滑十】从单幅图像中评估加性噪音的均方差。
  estimate_noise estimate_noise — Estimate the image noise from a single image.
用户1138785
2023/01/05
5700
【短道速滑十】从单幅图像中评估加性噪音的均方差。
动态规划“遇见”图像检索
两个对象的相似度的多少,统计学上常用的方法是对象在多维属性空间的距离来量化。同样图像也是对象的一种;
herain
2022/04/27
3380
动态规划“遇见”图像检索
【MATLAB】图像导出 ( 导出绘制的图像 | 图像设置 )
选择 matlab 生成的图形界面 " Figure 1 " 的菜单栏 , " 编辑选项 " , 点击 " 复制图形 " , 可以将图像拷贝到 Word 文档中 ;
韩曙亮
2023/03/29
10K0
【MATLAB】图像导出 ( 导出绘制的图像 | 图像设置 )
创建合成CT图像数据
本文我们描述了一种从一组小样本中创建合成医学图像的方法,我们的方法基于随机部分变形,因此无需深度学习(不需要GANs)。
小白学视觉
2020/07/20
1.2K0
创建合成CT图像数据
Android 图像处理(1)
操作的对象是每个像素,我们可以改变图像的色相(Hue)、饱和度(Saturation)、明度(Luminance) ColorActivity
用户3004328
2018/09/06
4960
Android 图像处理(1)
161. 旋转图像交换加转置
样例 给出一个矩形[[1,2],[3,4]],90度顺时针旋转后,返回[[3,1],[4,2]]
和蔼的zhxing
2018/09/04
3320
关于OpenCV中图像的widthStep
在OpenCV的IplImage指针结构中,有一个成员widthStep,这个值如何来确定呢,最近让我头疼了好久,终于想明白了,现在
全栈程序员站长
2022/07/01
5440
StarGAN - 图像到图像的翻译
通过输入来自两个不同领域的训练数据,StarGANs模型可以学习将某一个领域的图片转换成为另一个领域。
AI研习社
2019/05/08
8660
StarGAN - 图像到图像的翻译
点击加载更多

相似问题

用泛型处理构造函数中的类型擦除

55

在Java中围绕类型擦除设计构造函数

31

由于类型擦除而导致的模糊构造函数

13

Java中的类型擦除

12

Java类型擦除

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文