2011-10-11 19 views
8

ブーストジオメトリポリゴンを使って計算を行う簡単なDLLがあります。 (ほとんどの交差点と相違点)DLLはC#コードとDelphiから呼び出され、他の場所から知っているので、結果をすべて処理できる配列に変換する必要があります。ブーストジオメトリポリゴンからポイントの座標を取得する

更新日: 私はコードを単純化して多少修正しました。新しいコードは全く違って見え、まったく異なるアプローチ(for_each_point)を使用し、何らかの形でまだコンパイルされません。

私の新しいコード:

#include <vector> 
#include <boost/range.hpp> 
#include <boost/geometry.hpp> 
#include <boost/geometry/geometries/polygon.hpp> 

using namespace boost::geometry; 

typedef boost::geometry::model::point 
    < 
     double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree> 
    > spherical_point; 
class PointAggregator { 
private : 
    double *x, *y; 
    int count; 

public : 
    PointAggregator(int size) { 
     x = (double*) malloc(sizeof(double) * size); 
     y = (double*) malloc(sizeof(double) * size); 
     count = 0; 
    } 

    ~PointAggregator() { 
     free(x); 
     free(y); 
    } 

    inline void operator()(spherical_point& p) { 
     x[count] = get<0>(p); 
     y[count] = get<1>(p); 
     count++; 
    } 

    void GetResult(double *resultX, double *resultY) { 
     resultX = x; 
     resultY = y; 
    } 
}; 

void VectorToArray(std::vector<model::polygon<spherical_point>> resultVector, double x[], double y[], int *count) { 
    int i = 0;  
    for (std::vector<model::polygon<spherical_point>>::iterator it = resultVector.begin(); it != resultVector.end(); ++it) { 
     if (boost::size(*it) >= 2) { 
      *count = boost::size(*it); 
      PointAggregator* pa = new PointAggregator(*count); 
      boost::geometry::for_each_point(*it, *pa); 
      pa->GetResult(x, y); 
      delete(pa); 
      break; 
     }  
    } 
} 

現在のコンパイルエラーは、次のとおりです。

  1. エラーC2039: 'type' を '後押し:: MPL :: eval_if_c' イテレータのメンバーではありません。 hpp 63
  2. エラーC3203: 'type':テンプレートパラメータ 'Iterator'のテンプレート引数として未定義クラステンプレートを使用できません。実際の型が必要ですdifference_type.hpp 25
  3. エラーC2955: 「後押し::タイプを」:「後押し:: iterator_differenceを」:クラステンプレートを使用すると、テンプレート引数リストdifference_type.hpp 25
  4. エラーC2955を必要とするクラステンプレートを使用すると、テンプレート引数リストdifference_type.hpp 26

が必要ですどの部分がコードのこの部分(私のファイル名はgeometry.cpp)と関係がないように見えますが、Boost Geometryを使用しているものはすべてコメントアウトされていますが、まだこれらのエラーが発生します...

Here is my bad code that I had previously (edited by sehe)

(私はC++とBoostの新機能ですので、私は基本的なコンセプトを一緒にインターネットから入れています) 多分簡単にポリゴンを繰り返すことはできませんし、些細な部分も見逃してしまったり、ポリゴンをリングとして使うことができない、または反復がちょうど私が彼らがいると思った方法ではない、または私は他に何が間違っているか分からない。私は何を間違えたのですか?

+0

コンパイルエラーが発生していますか、ロジックエラーを探していますか?何があなたのために働いていないのですか? – sbrett

+0

私のコードを更新しました。私はコンパイルできないので、私は物事をまったく意味論的にまったくやっているのかどうか分からないので、何らかのエラーを探しています。 – ytg

+1

私のシステムで使っていたブーストバージョンは1.35だったので、SVNにあるものは何でも更新しました(私はすぐに1.48になると思います)。 私はboost :: geometryを持たないという問題を克服して、どんな種類のエラーが発生しているのかを正確に見ることができますが、それは面倒ですが、それほど多くはありません。私がboost_rangeであると考えるものの一部として定義されたboost :: sizeメソッドは、あなたのモデル:: polygon をどのように処理するか分からないようです。ブースト範囲参照を調べた後、range_beginなどの必要な機能について述べたことに気がつきました。 – sbrett

答えて

4

私が修正されるために必要ないくつかのことが見つかりました:私は見

  1. 一つの問題は、あなたのテンプレートです。スペースを入れてください!
  2. ブースト範囲は、先頭と末尾のペアを保持するコンテナまたは範囲に作用します。
  3. イテレータは、オブジェクトへのポインタのようなものを表します。イテレータのサイズを取得することは、あなたが望むことをしません。コンテナ全体のboost :: sizeまたはstd :: distance(begin_iterator、end_iterator)のどちらかを使用する必要があります。ここで

コンパイルしたバージョンです:

#include <vector> 
#include <boost/range.hpp> 
#include <boost/geometry.hpp> 
#include <boost/geometry/geometries/polygon.hpp> 

using namespace boost::geometry; 

typedef boost::geometry::model::point 
    < 
     double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree> 
    > spherical_point; 
class PointAggregator { 
private : 
    double *x, *y; 
    int count; 

public : 
    PointAggregator(int size) { 
     x = (double*) malloc(sizeof(double) * size); 
     y = (double*) malloc(sizeof(double) * size); 
     count = 0; 
    } 

    ~PointAggregator() { 
     free(x); 
     free(y); 
    } 

    inline void operator()(spherical_point& p) { 
     x[count] = get<0>(p); 
     y[count] = get<1>(p); 
     count++; 
    } 

    void GetResult(double *resultX, double *resultY) { 
     resultX = x; 
     resultY = y; 
    } 
}; 

// added spaces to the close brackets >> becomes > > 
void VectorToArray(std::vector<model::polygon<spherical_point> > resultVector, double x[], double y[], int *count) { 
    for (std::vector<model::polygon<spherical_point> >::iterator it = resultVector.begin(); it != resultVector.end(); ++it) { 
     if (boost::size(resultVector) >= 2) { 
      // getting the size of the whole container 
      *count = boost::size(resultVector); 
      PointAggregator* pa = new PointAggregator(*count); 
      boost::geometry::for_each_point(*it, *pa); 
      pa->GetResult(x, y); 
      delete(pa); 
      break; 
     }  
    } 
} 
+1

私は私の前にあなたの答えを見ませんでした。謝罪。 – sbrett

4

[OK]を、私はあなたがここに探しているものを持っていると思います。 私は2以上のポイントであると想定しているこの範囲を探している理由はまだ分かりませんが、少なくともboost :: size()を使用するとコンパイルする方法を考え出しました。

まずオフは、機能

void VectorToArray(std::vector<model::polygon<spherical_point> > resultVector, double x[], double y[], int *count) 
{ 
... 
} 

の最初のパラメータは型モデルのインスタンス::ポリゴンを含むスタンダード::ベクトルであることを理解します。

これは、あなたのイテレータを逆参照...

std::vector<model::polygon<spherical_point> >::iterator it 

として定義右辺値がモデル::多角形であることを意味しています。

boost :: model :: polygonはBoost.Rangeと互換性がありません。 ブースト::モデル::ポリゴンは

inline ring_type const& outer() const { return m_outer; } 
inline inner_container_type const& inners() const { return m_inners; } 
inline ring_type& outer() { return m_outer; } 
inline inner_container_type & inners() { return m_inners; } 
inline void clear() 
{ 
    m_outer.clear(); 
    m_inners.clear(); 
} 

これはあなたの*それ(すなわち、モデル::ポリゴン)関数のみを呼び出すに制限されていることを意味.... 5つのメンバ関数を含むタイプです。

あなたがしたいように見えるのは、ベクター内の各ポリゴンの外側のリングまたは内側のリングのいずれかをつかむことです(どちらが内側か外側かはわかりません)。そして、そのリングの範囲2以上です。

これを行うには、さらにmplとtypedefを実行する必要があります。

typedef boost::geometry::model::point<double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree> > spherical_point; // your definition of a spherical_point 
typedef boost::geometry::model::polygon<spherical_point> polygon; //consolidation of template args for a polygon 
typedef boost::geometry::ring_type<polygon>::type ring_type; // define a ring_type that can handle your spherical_point by way of the polygon typedef. 
typedef boost::geometry::interior_type<polygon>::type int_type; //define a interior_type that can handle your spherical_point 

これを完了し、ちょうど、それは私はあなたが条件付きのあなたの範囲を制限するための「外側」リングを望んでいたと仮定することを決定した「作業」取得します。

gcc 4.1.1とboost 1.48のコードをコンパイルするのはここです。 ロジックが正しいかどうかは他の誰かに任せます。

using namespace boost::geometry; 
typedef boost::geometry::model::point<double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree> > spherical_point; 
typedef boost::geometry::model::polygon<spherical_point> polygon; 
typedef boost::geometry::ring_type<polygon>::type ring_type; 
typedef boost::geometry::interior_type<polygon>::type int_type; 

class PointAggregator 
{ 
private : 
    double *x, *y; 
    int count; 

public : 
    PointAggregator(int size) 
    { 
     x = (double*) malloc(sizeof(double) * size); 
     y = (double*) malloc(sizeof(double) * size); 
     count = 0; 
    } 

    ~PointAggregator() 
    { 
     free(x); 
     free(y); 
    } 

    inline void operator()(spherical_point& p) 
    { 
     x[count] = get<0>(p); 
     y[count] = get<1>(p); 
     count++; 
    } 

    void GetResult(double *resultX, double *resultY) 
    { 
     resultX = x; 
     resultY = y; 
    } 
}; 

void VectorToArray(std::vector<model::polygon<spherical_point> > resultVector, double x[], double y[], int *count) 
{ 
    for (std::vector<model::polygon<spherical_point> >::iterator it = resultVector.begin(); it != resultVector.end(); ++it) 
    { 
     model::polygon<spherical_point> tmpPoly; 
     tmpPoly = (*it); 

     boost::geometry::ring_type<polygon>::type somering = tmpPoly.outer(); //typed it all out again instead of using ring_type since the complier was complaining and i didn't wanna get into it. 
     int ringsize = boost::size(somering); 
     if(ringsize >= 2) 
     { 

      *count = ringsize; 
      PointAggregator* pa = new PointAggregator(*count); 
      boost::geometry::for_each_point(*it, *pa); 
      pa->GetResult(x, y); 
      delete(pa); 
      break; 
     } 
    } 
} 
+0

私の心を読んで、外側の輪の様相を理解するという印象的な仕事。 – ytg

関連する問題