本文整理汇总了C++中NDArray::get_data方法的典型用法代码示例。如果您正苦于以下问题:C++ NDArray::get_data方法的具体用法?C++ NDArray::get_data怎么用?C++ NDArray::get_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NDArray
的用法示例。
在下文中一共展示了NDArray::get_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toDataCoords
/**
* @param pos A point in Qt screen coordinates from, for example, a mouse click
* @return A QPointF defining the position in data coordinates
*/
QPointF FigureCanvasQt::toDataCoords(QPoint pos) const {
// There is no isolated method for doing the transform on matplotlib's
// classes. The functionality is bound up inside other methods
// so we are forced to duplicate the behaviour here.
// The following code is derived form what happens in
// matplotlib.backends.backend_qt5.FigureCanvasQT &
// matplotlib.backend_bases.LocationEvent where we transform first to
// matplotlib's coordinate system, (0,0) is bottom left,
// and then to the data coordinates
const int dpiRatio(devicePixelRatio());
const double xPosPhysical = pos.x() * dpiRatio;
GlobalInterpreterLock lock;
// Y=0 is at the bottom
double height = PyFloat_AsDouble(
Python::Object(m_figure.pyobj().attr("bbox").attr("height")).ptr());
const double yPosPhysical =
((height / devicePixelRatio()) - pos.y()) * dpiRatio;
// Transform to data coordinates
QPointF dataCoords;
try {
auto invTransform = gca().pyobj().attr("transData").attr("inverted")();
NDArray transformed = invTransform.attr("transform_point")(
Python::NewRef(Py_BuildValue("(ff)", xPosPhysical, yPosPhysical)));
auto rawData = reinterpret_cast<double *>(transformed.get_data());
dataCoords =
QPointF(static_cast<qreal>(rawData[0]), static_cast<qreal>(rawData[1]));
} catch (Python::ErrorAlreadySet &) {
PyErr_Clear();
// an exception indicates no transform possible. Matplotlib sets this as
// an empty data coordinate so we will do the same
}
return dataCoords;
}