2

how boost::geometry私はのが機能していないことを理解しようとしfor_each_segmentます。ドキュメントにfor_each_segmentは、ジオメトリとファンクターが必要であると書かれています。私の例では、このファンクターが呼び出さpolylength_helperれます。このスニペットがコンパイルされていない限り、コンパイルされるまで単純にするために、そこで数値をインクリメントするだけです。

// foo.h

typedef boost::geometry::model::point<double, 2, bg::cs::cartesian> GeographicPoint;
typedef boost::geometry::model::linestring<GeographicPoint> GeographicPolyLine;
typedef boost::geometry::model::segment<GeographicPoint> GeographicSegment;

double poly_length(const GeographicPolyLine&);

template<typename Segment>
struct polylength_helper{
    polylength_helper() : length(0){};

    inline void operator()(Segment s){
        length += 1;
    };

    double length;
};

// foo.cpp

double poly_length(GeographicPolyLine &poly){
    polylength_helper<GeographicSegment> helper;
    bg::for_each_segment(poly, helper);
    return helper.length;
}

まあ、これはコンパイルされません。私clangはより理解しやすい出力に使用しました、それは言います:

note: candidate function not viable: no known
conversion from 'model::referring_segment<point_type>' to
'boost::geometry::model::segment<boost::geometry::model::point<double, 2,
  boost::geometry::cs::cartesian> >' for 1st argument
inline void operator()(Segment s){
            ^

誰かが私を助けることができますか?referring_segment特に、メッセージのどこから来たのかわかりません。

ドキュメントの例を次に示します。

http://www.boost.org/doc/libs/1_48_0/libs/geometry/doc/html/geometry/reference/algorithms/for_each/for_each_segment_2_const_version.html

しかし、sを除いて、これが私のバージョンとどのように異なるのか理解できませんtypedef

4

1 に答える 1

2

行を変更する

typedef boost::geometry::model::segment<GeographicPoint> GeographicSegment;

typedef boost::geometry::model::referring_segment<GeographicPoint> GeographicSegment;

これでコンパイルが完了します。


セグメントrefer_segmentに関するドキュメントから、2 つの唯一の違いは、 refer_segment がポイントへの参照を保持することです。これは、変更されたポイントが に反映される必要があるため、セグメントを変更する for each で必要なものですlinestring。ポイントを変更しない for each では、constコピーの量を減らすため、参照 (ほとんどの場合は参照) を取得する必要があります。

于 2011-12-09T23:03:45.843 に答える