Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将boost::geometry多边形转换为STL对象_C++_Boost_Boost Geometry - Fatal编程技术网

C++ 将boost::geometry多边形转换为STL对象

C++ 将boost::geometry多边形转换为STL对象,c++,boost,boost-geometry,C++,Boost,Boost Geometry,如何将boost::geometry多边形放入STL对象 我相信这一定很简单,因为我在文档中找不到示例。然而,我花了大约4个工作日来尝试做这件小事。我对C++(长时间R程序)很陌生,但是这些小数据转换的东西让我疯狂。p> 是的,有一个题目很像我的: 但是代码太复杂了(海报一直在改变它很多次),我不能做它的头或尾,也不能想象其他C++新手会。 这是一个简单的示例,应该转换为其他一些boost::geometry数据类型,希望所有人都能理解 #include <iostream>

如何将boost::geometry多边形放入STL对象

我相信这一定很简单,因为我在文档中找不到示例。然而,我花了大约4个工作日来尝试做这件小事。我对C++(长时间R程序)很陌生,但是这些小数据转换的东西让我疯狂。p> 是的,有一个题目很像我的:

但是代码太复杂了(海报一直在改变它很多次),我不能做它的头或尾,也不能想象其他C++新手会。

这是一个简单的示例,应该转换为其他一些boost::geometry数据类型,希望所有人都能理解

 #include <iostream>

 #include <boost/geometry.hpp>
 #include <boost/geometry/geometries/polygon.hpp>
 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>

 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)

 //One thing I tried is a function to use with `for_each_point()` so I set that up first.

  template <typename Point>
  void get_coordinates(Point const& p)
  {
  using boost::geometry::get;
  std::cout << get<0>(p) get<1>(p) << std::endl;
  }

  int main()
  {
  typedef boost::tuple<double, double> point;
  typedef boost::geometry::model::polygon<point> polygon;

  polygon poly;
  boost::geometry::read_wkt("polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6, 3.4 2.0, 4.1 3.0, 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7, 2.0 1.3))", poly);

   polygon hull;
   boost::geometry::convex_hull(poly, hull);

 // Now I know I can `dsv()` and print to the screen like this:

  using boost::geometry::dsv;
  std::cout
    << "hull: " << dsv(hull) << std::endl;

  // And/Or I can use my function with for_each_point()



  boost::geometry::for_each_point(hull, get_coordinates<point>);

return 0;
}
#包括
#包括
#包括
#包括
BOOST\u几何\u寄存器\u BOOST\u元组\u CS(CS::笛卡尔)
//我尝试过的一件事是使用一个函数来处理'for_each_point()',所以我首先设置了它。
模板
void get_坐标(点常量和点)
{
使用boost::geometry::get;

std::cout多边形已经采用STL容器格式,默认情况下,boost::geometry::polygon的外环和内环都存储有std::vector

考虑到您的评论,您可能需要:

多边形外壳;
几何体:凸面外壳(多边形,外壳);
boost::geometry::对于每个_点(boost::geometry::外部_环(外壳),获取_坐标);
如果将get_coordinates函数更正为(注意,例如:

boost::geometry::model::polygon<Point> polygon;
polygon.outer().push_back( point );
boost::geometry::model::polygon;
polygon.outer().向后推(点);
因此,polygon.outer()是std::vector(外部的,如Barende Gehrels所说)。
请参见此处:

您可以在boost模型中使用迭代器来迭代所有点,并将它们添加到您喜欢的任何类型的容器中

多边形模型稍微复杂一些,因为它们有一个外环,也可能有多个内环

假设您想要“外壳”对象(或任何多边形,包括原始“多边形”)外圈中的所有点,只需在其上迭代并逐点将它们添加到标准向量

如果需要x的向量和y的向量,请使用相同的方法

::std::vectorhullPoints;
:std::vectorhullx点;
:std::vectorhullYPoints;
//auto关键字使声明迭代器变得容易
for(auto-hulkliterator=hull.outer().begin;
hullIterator!=hull.outer().end();
++(文学家)
{
//对于点类型的向量,只需逐个添加点
船体点。向后推_(*hullPoints);
//对于x和y向量,从点提取x/y
hullx点。向后推(get(*hullx点));
hullYPoints.向后推(get(*hullliterator));
}

**我修复了代码中的一些错误,以使问题更符合您的答案。非常感谢您的回答,不幸的是我仍然没有得到答案。我花了很长时间试图破译这些错误,但在一百万年内,我从来没有想到如何抓住要点。让我问几个问题:1)如何确定多边形对象中的坐标点称为外环?我看到点、点列表、环列表、点、内环,但从未看到外环。2)如何确定外环存储为std::vector?3)如何知道使用
外环()
访问std::vector?4)即使我现在了解了所有这些,我仍然无法完成我通常期望使用std:vector可以完成的所有事情。例如:double vectSize=boost::geometry::exterior_ring(hull).size();//返回8,但尝试访问元素无效:double element1=boost::geometry::exterior_ring(外壳)[0];错误:无法在初始化中将“boost::tuples::tuple”转换为“double”:模型::多边形只是多边形概念的一个实例。而外部环通常对多边形概念有效。boost。几何体遵循OGC惯例,因此可能会为您的问题提供一些额外的说明……它不需要是std::vector它也可以是一个STD::DeQue.等等,它应该遵循Boosix.Orror概念.它都在文档中(HMM,它应该是在文档中的所有).我是如何理解的.我写了. 4:你应该首先让自己舒服的使用标准库.双VCuthSige=…C++程序员应该写int VistCsibe(或者更好:std::size\u t vectSize)。然后尝试将double element1设置为向量的元素,这是一个点…点不是double,一个点包含两个(或更多)double。因此,在您的示例中,您应该使用Boost.Tuple接口来获取x或y坐标。因此,您应该熟悉Boost.Tuple。。。
  template <typename Point>
  void get_coordinates(Point const& p)
  {
      using boost::geometry::get;
      std::cout << get<0>(p) << ", " << get<1>(p) << std::endl;
  }
boost::geometry::model::polygon<Point> polygon;
polygon.outer().push_back( point );