MantidQt::SliceViewer::PeakBoundingBox getPeakBoundingBoxForEllipsoid(
    const std::vector<Mantid::Kernel::V3D> &directions,
    const std::vector<double> &radii,
    const Mantid::Kernel::V3D &originEllipsoid) {
  // Get the length of largest projection onto x,y,z
  auto projectionLengths = getProjectionLengths(directions, radii);

  using namespace MantidQt::SliceViewer;

  // Corners
  EllipsoidPlaneSliceCalculator calc;
  auto zoomOutFactor = calc.getZoomOutFactor();
  const double leftValue =
      originEllipsoid.X() - zoomOutFactor * projectionLengths[0];
  const double rightValue =
      originEllipsoid.X() + zoomOutFactor * projectionLengths[0];
  const double bottomValue =
      originEllipsoid.Y() - zoomOutFactor * projectionLengths[1];
  const double topValue =
      originEllipsoid.Y() + zoomOutFactor * projectionLengths[1];

  Left left(leftValue);
  Right right(rightValue);
  Bottom bottom(bottomValue);
  Top top(topValue);
  SlicePoint slicePoint(originEllipsoid.Z());

  return PeakBoundingBox(left, right, top, bottom, slicePoint);
}
Example #2
0
/**
 * Convenience overload.
 * 
 * @param minBounds :: Near-bottom-left corner of the scene.
 * @param maxBounds :: Far-top-right corner of the scene.
 * @param type :: Projection type: ORTHO or PERSPECTIVE. PERSPECTIVE isn't fully implemented
 */
void Viewport::setProjection(const Mantid::Kernel::V3D& minBounds, const Mantid::Kernel::V3D& maxBounds, ProjectionType type)
{
  double radius = minBounds.norm();
  double tmp = maxBounds.norm();
  if (tmp > radius) radius = tmp;

  setProjection( minBounds.X(), maxBounds.X(), minBounds.Y(), maxBounds.Y(), -radius, radius, type );
}
/** Calculate the size of the detector in U/V
*
* @param udet :: UwrappedDetector struct to calculate the size for. udet's size
*fields
* are updated by this method.
*/
void UnwrappedSurface::calcSize(UnwrappedDetector &udet) {
  // U is the horizontal axis on the screen
  const Mantid::Kernel::V3D U(-1, 0, 0);
  // V is the vertical axis on the screen
  const Mantid::Kernel::V3D V(0, 1, 0);

  // find the detector's rotation
  Mantid::Kernel::Quat R;
  this->rotate(udet, R);

  Mantid::Geometry::BoundingBox bbox = udet.detector->shape()->getBoundingBox();
  Mantid::Kernel::V3D scale = udet.detector->getScaleFactor();

  // sizes of the detector along each 3D axis
  Mantid::Kernel::V3D size = bbox.maxPoint() - bbox.minPoint();
  size *= scale;

  Mantid::Kernel::V3D s1(size);
  Mantid::Kernel::V3D s2 = size + Mantid::Kernel::V3D(-size.X(), 0, 0) -
                           Mantid::Kernel::V3D(size.X(), 0, 0);
  Mantid::Kernel::V3D s3 = size + Mantid::Kernel::V3D(0, -size.Y(), 0) -
                           Mantid::Kernel::V3D(0, size.Y(), 0);
  // rotate the size vectors to get the dimensions along axes U and V
  R.rotate(s1);
  R.rotate(s2);
  R.rotate(s3);

  // get the larges projection to the U axis which is the visible width
  double d = fabs(s1.scalar_prod(U));
  udet.width = d;
  d = fabs(s2.scalar_prod(U));
  if (d > udet.width)
    udet.width = d;
  d = fabs(s3.scalar_prod(U));
  if (d > udet.width)
    udet.width = d;

  // get the larges projection to the V axis which is the visible height
  d = fabs(s1.scalar_prod(V));
  udet.height = d;
  d = fabs(s2.scalar_prod(V));
  if (d > udet.height)
    udet.height = d;
  d = fabs(s3.scalar_prod(V));
  if (d > udet.height)
    udet.height = d;

  // apply the scale factors
  udet.width *= udet.uscale;
  udet.height *= udet.vscale;

  // don't let them be too large
  if (udet.width > m_width_max)
    m_width_max = udet.width;
  if (udet.height > m_height_max)
    m_height_max = udet.height;
}
Example #4
0
void InstrumentWindowPickTab::updateSelectionInfo(int detid)
{
  if (m_instrWindow->blocked()) 
  {
    m_selectionInfoDisplay->clear();
    return;
  }
  if (detid >= 0)
  {
    InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
    Mantid::Geometry::IDetector_const_sptr det = instrActor->getInstrument()->getDetector(detid);
    QString text = "Selected detector: " + QString::fromStdString(det->getName()) + "\n";
    text += "Detector ID: " + QString::number(detid) + '\n';
    QString wsIndex;
    try {
      wsIndex = QString::number(instrActor->getWorkspaceIndex(detid));
      updatePlot(detid); // Update the plot if the detector links to some data
    } catch (Mantid::Kernel::Exception::NotFoundError) {
      // Detector doesn't have a workspace index relating to it
      wsIndex = "None";
      m_plot->clearCurve(); // Clear the plot window
      m_plot->replot();
    }
    text += "Workspace index: " + wsIndex + '\n';
    Mantid::Kernel::V3D pos = det->getPos();
    text += "xyz: " + QString::number(pos.X()) + "," + QString::number(pos.Y()) + "," + QString::number(pos.Z())  + '\n';
    double r,t,p;
    pos.getSpherical(r,t,p);
    text += "rtp: " + QString::number(r) + "," + QString::number(t) + "," + QString::number(p)  + '\n';
    Mantid::Geometry::ICompAssembly_const_sptr parent = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(det->getParent());
    if (parent)
    {
      QString textpath;
      while (parent)
      {
        textpath="/"+QString::fromStdString(parent->getName())+textpath;
        parent=boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(parent->getParent());
      }
      text += "Component path:" +textpath+"/"+ QString::fromStdString(det->getName()) +'\n';
    }
    const double integrated = instrActor->getIntegratedCounts(detid);
    const QString counts = integrated == -1.0 ? "N/A" : QString::number(integrated);
    text += "Counts: " + counts + '\n';
    m_selectionInfoDisplay->setText(text);
  }
  else
  {
    m_selectionInfoDisplay->clear();
    m_plot->clearCurve(); // Clear the plot window
    m_plot->replot();
  }
}
    void QPeaksTableModel::updateDataCache(const Mantid::Geometry::IPeak& peak, const int row) const
    {
      // if the index is what is already cached just return
      if (row == m_dataCachePeakIndex)
        return;

      // generate the cache
      m_dataCache.clear();
      m_dataCache.push_back(QString::number(peak.getRunNumber()));
      m_dataCache.push_back(QString::number(peak.getDetectorID()));
      m_dataCache.push_back(QString::number(peak.getH(), 'f', m_hklPrec));
      m_dataCache.push_back(QString::number(peak.getK(), 'f', m_hklPrec));
      m_dataCache.push_back(QString::number(peak.getL(), 'f', m_hklPrec));
      m_dataCache.push_back(QString::number(peak.getWavelength(), 'f', 4));
      double eI = peak.getInitialEnergy();
      double eF = peak.getFinalEnergy();
      m_dataCache.push_back(QString::number(eI, 'f', 4));
      m_dataCache.push_back(QString::number(eF, 'f', 4));
      m_dataCache.push_back(QString::number(eI - eF, 'f', 4));
      m_dataCache.push_back(QString::number(peak.getTOF(), 'f', 1));
      m_dataCache.push_back(QString::number(peak.getDSpacing(), 'f', 4));
      double intensity = peak.getIntensity();
      double sigma = peak.getSigmaIntensity();
      m_dataCache.push_back(QString::number(intensity, 'f', 1));
      m_dataCache.push_back(QString::number(sigma, 'f', 1));
      m_dataCache.push_back(QString::number(intensity/sigma, 'f', 2));
      m_dataCache.push_back(QString::number(peak.getBinCount(), 'g', 2));
      m_dataCache.push_back(QString(peak.getBankName().c_str()));
      m_dataCache.push_back(QString::number(peak.getRow()));
      m_dataCache.push_back(QString::number(peak.getCol()));

      const QString COMMA(",");

      const Mantid::Kernel::V3D qlab = peak.getQLabFrame();
      m_dataCache.push_back(QString::number(qlab.X(), 'f', 4) + COMMA + QString::number(qlab.Y(), 'f', 4) + COMMA + QString::number(qlab.Z(), 'f', 4));

      const Mantid::Kernel::V3D qsample = peak.getQSampleFrame();
      m_dataCache.push_back(QString::number(qsample.X(), 'f', 4) + COMMA + QString::number(qsample.Y(), 'f', 4) + COMMA + QString::number(qsample.Z(), 'f', 4));
    }
Example #6
0
/**
* Implementation of rendering Sample.
*/
void SampleActor::draw(bool picking) const {
  if (!picking && isVisible()) {
    OpenGLError::check("SampleActor::draw()");
    glPushAttrib(GL_ENABLE_BIT);
    GLboolean hasLight0;
    glGetBooleanv(GL_LIGHT0, &hasLight0);
    if (hasLight0) {
      glEnable(GL_LIGHTING);
    }
    glPushMatrix();
    m_color.paint();
    Mantid::Kernel::V3D pos = m_samplePos->getPos();
    glTranslated(pos.X(), pos.Y(), pos.Z());
    m_sample.getShape().draw();
    glPopMatrix();
    glPopAttrib();
    OpenGLError::check("SampleActor::draw()");
  }
}
 /**
 Implementation doesn't make sense on this type.
 @param distance : 
 @return weighting
 */
 double ParabolicWeighting::weightAt(const Mantid::Kernel::V3D& distance)
 {
   return static_cast<double>(m_cutOff - std::abs(distance.X()) + m_cutOff - std::abs(distance.Y()) + 1);
 }
/**
 * Update the info window with information for a selected detector.
 * @param detid :: ID of the selected detector.
 */
void InstrumentWindowPickTab::updateSelectionInfo(int detid)
{
    if (m_freezePlot)
    {   // freeze the plot for one update
        m_freezePlot = false;
        return;
    }
    if (m_instrWindow->blocked())
    {
        m_selectionInfoDisplay->clear();
        return;
    }
    if (detid >= 0)
    {
        InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
        Mantid::Geometry::IDetector_const_sptr det = instrActor->getInstrument()->getDetector(detid);
        QString text = "Selected detector: " + QString::fromStdString(det->getName()) + "\n";
        text += "Detector ID: " + QString::number(detid) + '\n';
        QString wsIndex;
        try {
            wsIndex = QString::number(instrActor->getWorkspaceIndex(detid));
            updatePlot(detid); // Update the plot if the detector links to some data
        } catch (Mantid::Kernel::Exception::NotFoundError &) {
            // Detector doesn't have a workspace index relating to it
            wsIndex = "None";
            m_plot->clearCurve(); // Clear the plot window
            m_plot->replot();
        }
        text += "Workspace index: " + wsIndex + '\n';
        Mantid::Kernel::V3D pos = det->getPos();
        text += "xyz: " + QString::number(pos.X()) + "," + QString::number(pos.Y()) + "," + QString::number(pos.Z())  + '\n';
        double r,t,p;
        pos.getSpherical(r,t,p);
        text += "rtp: " + QString::number(r) + "," + QString::number(t) + "," + QString::number(p)  + '\n';
        Mantid::Geometry::ICompAssembly_const_sptr parent = boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(det->getParent());
        if (parent)
        {
            QString textpath;
            while (parent)
            {
                textpath="/"+QString::fromStdString(parent->getName())+textpath;
                parent=boost::dynamic_pointer_cast<const Mantid::Geometry::ICompAssembly>(parent->getParent());
            }
            text += "Component path:" +textpath+"/"+ QString::fromStdString(det->getName()) +'\n';
        }
        const double integrated = instrActor->getIntegratedCounts(detid);
        const QString counts = integrated == -1.0 ? "N/A" : QString::number(integrated);
        text += "Counts: " + counts + '\n';
        QString xUnits;
        if (m_selectionType > SingleDetectorSelection && !m_plotSum)
        {
            switch(m_tubeXUnits)
            {
            case DETECTOR_ID:
                xUnits = "Detector ID";
                break;
            case LENGTH:
                xUnits = "Length";
                break;
            case PHI:
                xUnits = "Phi";
                break;
            default:
                xUnits = "Detector ID";
            }
        }
        else
        {
            xUnits = QString::fromStdString(instrActor->getWorkspace()->getAxis(0)->unit()->caption());
            //xUnits = "Time of flight";
        }
        text += "X units: " + xUnits + '\n';
        m_selectionInfoDisplay->setText(text);
    }
    else
    {
        m_selectionInfoDisplay->clear();
        m_plot->clearCurve(); // Clear the plot window
        m_plot->replot();
    }
}