获得点的坐标从升压几何多边形 [英] Getting the coordinates of points from a Boost Geometry polygon

查看:188
本文介绍了获得点的坐标从升压几何多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的DLL做一些计算与升压几何多边形。 (主要路口和差异。)由于DLL将最有可能从C#code调用,德尔福,谁在那里别人知道,我应该将结果转换成一切都可以处理数组。

I have a simple DLL doing some calculations with Boost Geometry polygons. (Mostly intersections and differences.) Since the DLL will be most likely called from C# code, and from Delphi and who knows from where else, I should convert the result into arrays that everything can handle.

更新:
我已经简化了,有点纠正我的code。新的code看起来完全不同,采用了完全不同的方法( for_each_point ),并以某种方式仍然不能编译。

UPDATE: I had simplified and somewhat corrected my code. The new code looks completely different, uses a completely different approach (for_each_point), and somehow still doesn't compile.

我的新code:

#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;
        }       
    }
}

目前的编译错误是:

The current compilation errors are:


  1. 错误C2039:类型:不是的boost :: MPL :: eval_if_c成员iterator.hpp 63

  2. 错误C3203:类型:非特类模板不能作为模板参数迭代模板参数,预计一个真正的类型difference_type.hpp 25

  3. 错误C2955:'的boost ::类型:使用类模板需要模板参数列表difference_type.hpp 25

  4. 错误C2955:'的boost :: iterator_difference:使用类模板需要模板参数列表difference_type.hpp 26

哪几个不喜欢看他们有什么关系code的这部分(我的文件名是geometry.cpp),但一切使用升压几何被注释掉了,我仍然得到这些错误,因此, ...

Which ones don't look like they have anything to do with this part of code (my filename is geometry.cpp), but everything else that uses Boost Geometry is commented out and I still get these errors, so...

这里是我的坏code,我不得不previously(由sehe编辑)

(我是新的C ++和Boost所以我可能会错过一些基本的概念,而把code从互联网在一起。)
我以为我可以不通过多边形进行迭代很容易,我错过了不平凡的一部分,或者说,一个多边形不能用作环或迭代只是没有我以为的方式本身,或者我没有想法还有什么可以是错误的。我做了什么错了?

(I'm new to C++ and Boost so I might have missed some basic concept while putting code from the internet together.) I assume that I can just not iterate through a polygon that easily and I missed the non-trivial part, or that a polygon can not be used as a ring, or iterations are just not the way I thought they are, or I have no idea what else can be wrong. What did I do wrong?

推荐答案

我发现,需要修复的几件事情:

I found a few things that needed to be fixed:


  1. 一个问题我看到的是在你的模板。一定要放空间!

  2. 升压范围适用于容器或持有开头的范围,最终对

  3. 重新迭代器presents像一个指向对象。获取迭代器的大小将不会做你想做的。您需要为使用整个容器的boost ::大小,或std ::距离(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;
        }       
    }
}

这篇关于获得点的坐标从升压几何多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆