質問する
739 次
1

自分の型を として登録する方法がわかりませんboost::geometry::model::ring。私は自分のポイントクラスを持っています:

struct Point { double x, y; };

また、リングは として保存されstd::vector<Point>ます。したがって、私はそれらを次のように登録しました:

BOOST_GEOMETRY_REGISTER_POINT_2D(Point , double, cs::cartesian, x, y);
BOOST_GEOMETRY_REGISTER_RING(std::vector<Point>);

ここで、リングの向きを修正したいと思います。実際、次のようにコンパイルされます。

void foo(std::vector<Point>& ring) {
  boost::geometry::correct(ring);
}

問題は、リングの「正しい」方向をどのように定義できるかということです。boost::geometry::model::polygonテンプレート パラメーターを使用すると、予想される方向を指定できます。ただし、以下はコンパイルされません。

void foo(std::vector<Point>& ring) {
    typedef boost::geometry::model::polygon<vector> clockwise_closed_polygon;
    clockwise_closed_polygon cwcp;
    boost::geometry::exterior_ring(cwcp) = ring; //<<< fails to compile
    boost::geometry::correct(cwcp);
}

どうやら、自分のリング タイプを で定義されたものに変換できないようclockwise_closed_polygonです。

だから私は2つの質問があります:

  1. 正しいリングの向きを指定するにはどうすればよいですか?
  2. 上記で宣言されているように、リング タイプをポリゴンで使用できないのはなぜですか?
4

1 に答える 1

3

問題は、リングの「正しい」向きをどのように定義できるかということです。

boost :: geometry :: point_order:を特殊化しようとするかもしれません。

ライブデモ

#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/ring.hpp>
#include <boost/geometry/geometries/geometries.hpp> 
#include <boost/geometry/core/point_order.hpp> 
#include <boost/geometry.hpp>
#include <iostream>
#include <ostream>
#include <vector>

using namespace boost::geometry;
using namespace std;

struct Point { double x, y; };

BOOST_GEOMETRY_REGISTER_POINT_2D(Point , double, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_RING(vector<Point>)

namespace boost { namespace geometry
{
   template<>
   struct point_order<vector<Point>>
   {
      //static const order_selector value=counterclockwise;
      static const order_selector value=clockwise;
   };
}}

template<typename Ring>
void print(const Ring &r)
{
   for(auto p : r)
      cout << "(" << p.x << "," << p.y << ")";
   cout << endl;
}

int main()
{
   std::vector<Point> ring{{0.0,0.0},{1.0,0.0},{0.0,1.0},{0.0,0.0}};
   print(ring);
   correct(ring);
   print(ring);
}

出力は次のとおりです。

(0,0)(1,0)(0,1)(0,0)
(0,0)(0,1)(1,0)(0,0)

時計回りから反時計回りに変更すると、出力は次のようになります。

(0,0)(1,0)(0,1)(0,0)
(0,0)(1,0)(0,1)(0,0)
于 2013-03-15T23:53:38.520 に答える