当前位置: 首页>>代码示例>>C++>>正文


C++ NDArray::get_data方法代码示例

本文整理汇总了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;
}
开发者ID:mantidproject,项目名称:mantid,代码行数:37,代码来源:FigureCanvasQt.cpp


注:本文中的NDArray::get_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。