Esempio n. 1
0
void InstrumentWindowPickTab::updatePlot(int detid)
{
  if (m_instrWindow->blocked())
  {
    m_plot->clearCurve();
    return;
  }
  if (m_plotPanel->isCollapsed()) return;
  InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
  Mantid::API::MatrixWorkspace_const_sptr ws = instrActor->getWorkspace();
  if (detid >= 0)
  {
    if (m_one->isChecked() || m_peak->isChecked())
    {// plot spectrum of a single detector
      plotSingle(detid);
    }
    else if (m_tube->isChecked())
    {// plot integrals
      plotTube(detid);
    }
  }
  else
  {
    m_plot->clearCurve();
  }
  m_plot->recalcAxisDivs();
  m_plot->replot();
}
Esempio n. 2
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 InstrumentWidgetRenderTab::showEvent(QShowEvent *) {
  auto surface = getSurface();
  if (surface) {
    surface->setInteractionMode(ProjectionSurface::MoveMode);
  }
  InstrumentActor *actor = m_instrWidget->getInstrumentActor();
  if (actor) {
    auto visitor = SetAllVisibleVisitor(actor->areGuidesShown());
    actor->accept(visitor);
    getSurface()->updateView();
    getSurface()->requestRedraw();
  }
}
Esempio n. 4
0
void InstrumentWindowPickTab::getBinMinMaxIndex(size_t wi,size_t& imin, size_t& imax)
{
  InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
  Mantid::API::MatrixWorkspace_const_sptr ws = instrActor->getWorkspace();
  const Mantid::MantidVec& x = ws->readX(wi);
  if (instrActor->wholeRange())
  {
    imin = 0;
    imax = x.size() - 1;
  }
  else
  {
    Mantid::MantidVec::const_iterator x_begin = std::lower_bound(x.begin(),x.end(),instrActor->minBinValue());
    Mantid::MantidVec::const_iterator x_end = std::lower_bound(x.begin(),x.end(),instrActor->maxBinValue());
    imin = static_cast<size_t>(x_begin - x.begin());
    imax = static_cast<size_t>(x_end - x.begin()) - 1;
  }
}
Esempio n. 5
0
/**
 * Plot data for a detector.
 * @param detid :: ID of the detector to be plotted.
 */
void InstrumentWindowPickTab::plotSingle(int detid)
{
  m_plot->clearLabels();
  InstrumentActor* instrActor = m_instrWindow->getInstrumentActor();
  Mantid::API::MatrixWorkspace_const_sptr ws = instrActor->getWorkspace();
  size_t wi;
  try {
    wi = instrActor->getWorkspaceIndex(detid);
  } catch (Mantid::Kernel::Exception::NotFoundError) {
    return; // Detector doesn't have a workspace index relating to it
  }
  // get the data
  const Mantid::MantidVec& x = ws->readX(wi);
  const Mantid::MantidVec& y = ws->readY(wi);

  // find min and max for x
  size_t imin,imax;
  getBinMinMaxIndex(wi,imin,imax);

  Mantid::MantidVec::const_iterator y_begin = y.begin() + imin;
  Mantid::MantidVec::const_iterator y_end = y.begin() + imax;

  m_plot->setXScale(x[imin],x[imax]);

  // fins min and max for y
  Mantid::MantidVec::const_iterator min_it = std::min_element(y_begin,y_end);
  Mantid::MantidVec::const_iterator max_it = std::max_element(y_begin,y_end);
  // set the data 
  m_plot->setData(&x[0],&y[0],static_cast<int>(y.size()));
  m_plot->setYScale(*min_it,*max_it);

  // find any markers
  ProjectionSurface* surface = mInstrumentDisplay->getSurface();
  if (surface)
  {
    QList<PeakMarker2D*> markers = surface->getMarkersWithID(detid);
    foreach(PeakMarker2D* marker,markers)
    {
      m_plot->addLabel(new PeakLabel(marker));
      //std::cerr << marker->getLabel().toStdString() << std::endl;
    }
  }
/**
* Respond to external change of the colormap.
*/
void InstrumentWidgetRenderTab::colorMapChanged() {
  InstrumentActor *instrumentActor = m_instrWidget->getInstrumentActor();
  setupColorBar(instrumentActor->getColorMap(), instrumentActor->minValue(),
                instrumentActor->maxValue(),
                instrumentActor->minPositiveValue(),
                instrumentActor->autoscaling());
}
InstrumentRenderer::InstrumentRenderer(const InstrumentActor &actor)
    : m_actor(actor), m_isUsingLayers(false) {

  m_displayListId[0] = 0;
  m_displayListId[1] = 0;
  m_useDisplayList[0] = false;
  m_useDisplayList[1] = false;

  const auto &componentInfo = actor.componentInfo();
  size_t textureIndex = 0;
  for (size_t i = componentInfo.root(); !componentInfo.isDetector(i); --i) {
    auto type = componentInfo.componentType(i);
    if (type == ComponentType::Rectangular ||
        type == ComponentType::OutlineComposite ||
        type == ComponentType::Grid) {
      m_textures.emplace_back(componentInfo, i);
      m_reverseTextureIndexMap[i] = textureIndex;
      textureIndex++;
    }
  }
}
/**
 * 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();
    }
}