Cythonic 方式包装 boost::geometry::P oint accessors
Cythonic way to wrap boost::geometry::Point accessors
包装
boost::geometry::Point
的以下成员函数的正确cythonic方法是什么?代码片段来自这里。
/// @brief Get a coordinate
/// @tparam K coordinate to get
/// @return the coordinate
template <std::size_t K>
inline CoordinateType const& get() const
{
#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
BOOST_GEOMETRY_ASSERT(m_created == 1);
BOOST_GEOMETRY_ASSERT(m_values_initialized[K] == 1);
#endif
BOOST_STATIC_ASSERT(K < DimensionCount);
return m_values[K];
}
/// @brief Set a coordinate
/// @tparam K coordinate to set
/// @param value value to set
template <std::size_t K>
inline void set(CoordinateType const& value)
{
#if defined(BOOST_GEOMETRY_ENABLE_ACCESS_DEBUGGING)
BOOST_GEOMETRY_ASSERT(m_created == 1);
m_values_initialized[K] = 1;
#endif
BOOST_STATIC_ASSERT(K < DimensionCount);
m_values[K] = value;
}
我第一次尝试使用:
cdef extern from "s57/data/geometries.h" namespace "bg::model":
cdef cppclass _Geo2 "bg::model::point<double, 2, bg::cs::spherical_equatorial<bg::degree>>":
_Geo2()
_Geo2( const _Geo2& other )
const double get[size_t]() except +
void set[size_t](double) except +
但后来我不知道该去哪里,因为像这样:
property x:
def __set__(self, double value):
deref(self._p).set[0](value)
给了我这个失败:
Error compiling Cython file:
------------------------------------------------------------
...
property x:
def __set__(self, double value):
deref(self._p).set[0](value)
^
------------------------------------------------------------
c:XXXXx.pyx:24:31: not parsable as a type
我目前的工作解决方案是创建一些辅助函数,例如:
double get_geo2_x( geo2& pnt );
double get_geo2_y( geo2& pnt );
void set_geo2_x( geo2& pnt, double value );
void set_geo2_y( geo2& pnt, double value );
有人想到了一个更优雅的解决方案吗?
您在处理非类型模板参数时遇到了问题。您可以使用字符串手动指定函数名称,这些字符串直接插入到生成的 C 代码中(请参阅 http://docs.cython.org/src/userguide/external_C_code.html#resolving-naming-conflicts-c-name-specifications)
作为一个非常简单的例子
// example.hpp
#include <iostream>
class C {
template <int K>
void set(double value) {
std::cout << K << ": " << value << std::endl;
}
和赛通密码
cdef extern from "example.hpp":
cdef cppclass C:
void set0 "set<0>"(double) except +
void set1 "set<1>"(double) except +
def do_set():
# very simple illustrative example
cdef C c
c.set0(1.0)
c.set1(1.5)
}
每当Cython看到set0
被调用C
时,它就会替换set<0>
,直接调用模板函数。然后,您可以像尝试的那样使用属性。
这可能并不比创建帮助程序函数好得多,但可能会容易一些。
相关文章:
- 将 vector<dlib::p oint> 转换为 NSArray,以便将其传递给 Swift 类
- Cythonic 方式包装 boost::geometry::P oint accessors
- 使用 cv::P oint 作为参数访问图像
- 将<Point2f> openCV 的向量转换为 Collections::Generic::List<Windows::P oint> of C#
- 将两个 std::vector<cv::P oint> 向量和安全公共点与第三个 std::vector<cv::P oint 进行比较>
- 如何使用 boost::geometry::d istance with opencv cv::P oint.
- 从 std::vector<cv::P oint>::const_iterator 中检索值
- 错误消息:与调用"(cv::Rect) (cv::Mat&, cv::P oint_, cv:<int>:P oint, cv::Scalar, int)"的调用不匹配
- 我在C++中遇到错误 - 错误:无法将"cv::P oint_"转换为"cv::P oint* <int>{aka cv::P oint_<int>*}" 作为回报