Пример #1
0
/**
 * Creates the output workspace for this algorithm
 * @param inputWorkspace A parent workspace to initialize from.
 * @return A pointer to the output workspace.
 */
API::MatrixWorkspace_sptr Transpose::createOutputWorkspace(
    API::MatrixWorkspace_const_sptr inputWorkspace) {
  Mantid::API::Axis *yAxis = getVerticalAxis(inputWorkspace);
  const size_t oldNhist = inputWorkspace->getNumberHistograms();
  const MantidVec &inX = inputWorkspace->readX(0);
  const size_t oldYlength = inputWorkspace->blocksize();
  const size_t oldVerticalAxislength = yAxis->length();

  // The input Y axis may be binned so the new X data should be too
  size_t newNhist(oldYlength), newXsize(oldVerticalAxislength),
      newYsize(oldNhist);
  MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create(
      inputWorkspace, newNhist, newXsize, newYsize);

  // Create a new numeric axis for Y the same length as the old X array
  // Values come from input X
  API::NumericAxis *newYAxis(nullptr);
  if (inputWorkspace->isHistogramData()) {
    newYAxis = new API::BinEdgeAxis(inX);
  } else {
    newYAxis = new API::NumericAxis(inX);
  }

  newYAxis->unit() = inputWorkspace->getAxis(0)->unit();
  outputWorkspace->getAxis(0)->unit() = inputWorkspace->getAxis(1)->unit();
  outputWorkspace->replaceAxis(1, newYAxis);
  setProperty("OutputWorkspace", outputWorkspace);
  return outputWorkspace;
}
Пример #2
0
/**
 * Creates the output workspace for this algorithm
 * @param inputWorkspace A parent workspace to initialize from.
 * @return A pointer to the output workspace.
 */
API::MatrixWorkspace_sptr Transpose::createOutputWorkspace(
    API::MatrixWorkspace_const_sptr inputWorkspace) {
  Mantid::API::Axis *yAxis = getVerticalAxis(inputWorkspace);
  const size_t oldNhist = inputWorkspace->getNumberHistograms();
  const auto &inX = inputWorkspace->x(0);
  const size_t oldYlength = inputWorkspace->blocksize();
  const size_t oldVerticalAxislength = yAxis->length();

  // The input Y axis may be binned so the new X data should be too
  size_t newNhist(oldYlength), newXsize(oldVerticalAxislength),
      newYsize(oldNhist);
  MatrixWorkspace_sptr outputWorkspace = inputWorkspace->cloneEmpty();
  outputWorkspace->initialize(newNhist, newXsize, newYsize);
  outputWorkspace->setTitle(inputWorkspace->getTitle());
  outputWorkspace->setComment(inputWorkspace->getComment());
  outputWorkspace->copyExperimentInfoFrom(inputWorkspace.get());
  outputWorkspace->setYUnit(inputWorkspace->YUnit());
  outputWorkspace->setYUnitLabel(inputWorkspace->YUnitLabel());
  outputWorkspace->setDistribution(inputWorkspace->isDistribution());

  // Create a new numeric axis for Y the same length as the old X array
  // Values come from input X
  API::NumericAxis *newYAxis(nullptr);
  if (inputWorkspace->isHistogramData()) {
    newYAxis = new API::BinEdgeAxis(inX.rawData());
  } else {
    newYAxis = new API::NumericAxis(inX.rawData());
  }

  newYAxis->unit() = inputWorkspace->getAxis(0)->unit();
  outputWorkspace->getAxis(0)->unit() = inputWorkspace->getAxis(1)->unit();
  outputWorkspace->replaceAxis(1, newYAxis);
  setProperty("OutputWorkspace", outputWorkspace);
  return outputWorkspace;
}
Пример #3
0
void Ellipse::setVertex(int i, const QPointF& v)
{
    // Save vertical axis vector.
    const QVector2D& vAxis  = getVerticalAxis();

    // If changed one of the two rotation-controlling points, adjust the other two points.
    if (i == 0 || i == 2)
    {
        // Transformation ellipse_t --> circle.
        QTransform transform = toUnitCircle();

        // Change the vertex.
        _rawSetVertex(i, v);

        // Combine with transformation circle -> ellipse_{t+1}.
        transform *= fromUnitCircle();

        // Set vertices.
        MShape::setVertex(1, transform.map( getVertex(1) ));
        MShape::setVertex(3, transform.map( getVertex(3) ));
        if (hasCenterControl())
            MShape::setVertex(4, transform.map( getVertex(4) ));
    }

    // If changed one of the two other points, just change the vertical axis.
    else if (i == 1 || i == 3)
    {
        // Retrieve the new horizontal axis vector and center.
        const QVector2D center(getCenter());

        QVector2D vFromCenter = QVector2D(v) - center;

        // Find projection of v onto vAxis / 2.
        QVector2D vAxisNormalized = vAxis.normalized();
        const QVector2D& projection = QVector2D::dotProduct( vFromCenter, vAxisNormalized ) * vAxisNormalized;

        // Assign vertical control points.
        QPointF v1;
        QPointF v3;
        if (i == 1)
        {
            v1 = (center + projection).toPointF();
            v3 = (center - projection).toPointF();
        }
        else
        {
            v1 = (center - projection).toPointF();
            v3 = (center + projection).toPointF();
        }

        // Transformation ellipse_t --> circle.
        QTransform transform = toUnitCircle();

        // Change vertical points.
        _rawSetVertex(1, v1);
        _rawSetVertex(3, v3);

        // Combine with transformation circle -> ellipse_{t+1}.
        transform *= fromUnitCircle();

        // Set vertices.
        if (hasCenterControl())
            _rawSetVertex(4, transform.map( getVertex(4) ));
    }

    // Center control point (make sure it stays inside!).
    else if (hasCenterControl())
    {
        // Clip control point.
        _rawSetVertex(4, clipInside(v));
    }

    // Just to be sure.
    sanitize();
}