Beispiel #1
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;
    }
  }
void InstrumentWidget::setSurfaceType(int type) {
  // we cannot do 3D without OpenGL
  if (type == FULL3D && !isGLEnabled()) {
    QMessageBox::warning(
        this, "Mantid - Warning",
        "OpenGL must be enabled to render the instrument in 3D.");
    return;
  }

  if (type < RENDERMODE_SIZE) {
    QApplication::setOverrideCursor(Qt::WaitCursor);
    SurfaceType surfaceType = SurfaceType(type);
    if (!m_instrumentActor)
      return;

    ProjectionSurface *surface = getSurface().get();
    int peakLabelPrecision = 6;
    bool showPeakRow = true;
    bool showPeakLabels = true;
    bool showPeakRelativeIntensity = true;
    if (surface) {
      peakLabelPrecision = surface->getPeakLabelPrecision();
      showPeakRow = surface->getShowPeakRowsFlag();
      showPeakLabels = surface->getShowPeakLabelsFlag();
    } else {
      QSettings settings;
      settings.beginGroup(InstrumentWidgetSettingsGroup);
      peakLabelPrecision = settings.value("PeakLabelPrecision", 2).toInt();
      showPeakRow = settings.value("ShowPeakRows", true).toBool();
      showPeakLabels = settings.value("ShowPeakLabels", true).toBool();

      // By default this is should be off for now.
      showPeakRelativeIntensity =
          settings.value("ShowPeakRelativeIntensities", false).toBool();
      settings.endGroup();
    }

    // Surface factory
    // If anything throws during surface creation, store error message here
    QString errorMessage;
    try {
      const auto &componentInfo = m_instrumentActor->componentInfo();
      if (!componentInfo.hasSample()) {
        throw InstrumentHasNoSampleError();
      }
      auto sample_pos = componentInfo.samplePosition();
      auto axis = getSurfaceAxis(surfaceType);

      m_maskTab->setDisabled(false);

      // create the surface
      if (surfaceType == FULL3D) {
        m_renderTab->forceLayers(false);

        if (m_instrumentActor->hasGridBank())
          m_maskTab->setDisabled(true);

        surface = new Projection3D(m_instrumentActor.get(),
                                   getInstrumentDisplayWidth(),
                                   getInstrumentDisplayHeight());
      } else if (surfaceType <= CYLINDRICAL_Z) {
        m_renderTab->forceLayers(true);
        surface =
            new UnwrappedCylinder(m_instrumentActor.get(), sample_pos, axis);
      } else if (surfaceType <= SPHERICAL_Z) {
        m_renderTab->forceLayers(true);
        surface =
            new UnwrappedSphere(m_instrumentActor.get(), sample_pos, axis);
      } else // SIDE_BY_SIDE
      {
        m_renderTab->forceLayers(true);
        surface = new PanelsSurface(m_instrumentActor.get(), sample_pos, axis);
      }
    } catch (InstrumentHasNoSampleError &) {
      QApplication::restoreOverrideCursor();
      throw;
    } catch (std::exception &e) {
      errorMessage = e.what();
    } catch (...) {
      errorMessage = "Unknown exception thrown.";
    }
    if (!errorMessage.isNull()) {
      // if exception was thrown roll back to the current surface type.
      QApplication::restoreOverrideCursor();
      QMessageBox::critical(
          this, "MantidPlot - Error",
          "Surface cannot be created because of an exception:\n\n  " +
              errorMessage + "\n\nPlease select a different surface type.");
      // if suface change was initialized by the GUI this should ensure its
      // consistency
      emit surfaceTypeChanged(m_surfaceType);
      return;
    }
    // end Surface factory

    m_surfaceType = surfaceType;
    surface->setPeakLabelPrecision(peakLabelPrecision);
    surface->setShowPeakRowsFlag(showPeakRow);
    surface->setShowPeakLabelsFlag(showPeakLabels);
    surface->setShowPeakRelativeIntensityFlag(showPeakRelativeIntensity);
    // set new surface
    setSurface(surface);

    // init tabs with new surface
    foreach (InstrumentWidgetTab *tab, m_tabs) { tab->initSurface(); }

    connect(surface, SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),
            this, SLOT(executeAlgorithm(Mantid::API::IAlgorithm_sptr)));
    connect(surface, SIGNAL(updateInfoText()), this, SLOT(updateInfoText()),
            Qt::QueuedConnection);
    QApplication::restoreOverrideCursor();
  }
Beispiel #3
0
void InstrumentWindow::setSurfaceType(int type) {
    // we cannot do 3D without OpenGL
    if (type == FULL3D && !isGLEnabled()) {
        QMessageBox::warning(
            this, "Mantid - Warning",
            "OpenGL must be enabled to render the instrument in 3D.");
        return;
    }

    if (type < RENDERMODE_SIZE) {
        QApplication::setOverrideCursor(Qt::WaitCursor);
        SurfaceType surfaceType = SurfaceType(type);
        if (!m_instrumentActor)
            return;

        ProjectionSurface *surface = getSurface().get();
        int peakLabelPrecision = 6;
        bool showPeakRow = true;
        bool showPeakLabels = true;
        if (surface) {
            peakLabelPrecision = surface->getPeakLabelPrecision();
            showPeakRow = surface->getShowPeakRowsFlag();
            showPeakLabels = surface->getShowPeakLabelsFlag();
        } else {
            QSettings settings;
            peakLabelPrecision =
                settings.value("Mantid/InstrumentWindow/PeakLabelPrecision", 2)
                .toInt();
            showPeakRow =
                settings.value("Mantid/InstrumentWindow/ShowPeakRows", true).toBool();
            showPeakLabels =
                settings.value("Mantid/InstrumentWindow/ShowPeakLabels", true)
                .toBool();
        }

        // Surface factory
        // If anything throws during surface creation, store error message here
        QString errorMessage;
        try {
            Mantid::Geometry::Instrument_const_sptr instr =
                m_instrumentActor->getInstrument();
            Mantid::Geometry::IComponent_const_sptr sample = instr->getSample();
            if (!sample) {
                throw InstrumentHasNoSampleError();
            }
            Mantid::Kernel::V3D sample_pos = sample->getPos();
            Mantid::Kernel::V3D axis;
            // define the axis
            if (surfaceType == SPHERICAL_Y || surfaceType == CYLINDRICAL_Y) {
                axis = Mantid::Kernel::V3D(0, 1, 0);
            } else if (surfaceType == SPHERICAL_Z || surfaceType == CYLINDRICAL_Z) {
                axis = Mantid::Kernel::V3D(0, 0, 1);
            } else if (surfaceType == SPHERICAL_X || surfaceType == CYLINDRICAL_X) {
                axis = Mantid::Kernel::V3D(1, 0, 0);
            } else // SIDE_BY_SIDE
            {
                axis = Mantid::Kernel::V3D(0, 0, 1);
            }

            // create the surface
            if (surfaceType == FULL3D) {
                surface =
                    new Projection3D(m_instrumentActor, getInstrumentDisplayWidth(),
                                     getInstrumentDisplayHeight());
            } else if (surfaceType <= CYLINDRICAL_Z) {
                surface = new UnwrappedCylinder(m_instrumentActor, sample_pos, axis);
            } else if (surfaceType <= SPHERICAL_Z) {
                surface = new UnwrappedSphere(m_instrumentActor, sample_pos, axis);
            } else // SIDE_BY_SIDE
            {
                surface = new PanelsSurface(m_instrumentActor, sample_pos, axis);
            }
        } catch (InstrumentHasNoSampleError &) {
            QApplication::restoreOverrideCursor();
            throw;
        } catch (std::exception &e) {
            errorMessage = e.what();
        } catch (...) {
            errorMessage = "Unknown exception thrown.";
        }
        if (!errorMessage.isNull()) {
            // if exception was thrown roll back to the current surface type.
            QApplication::restoreOverrideCursor();
            QMessageBox::critical(
                this, "MantidPlot - Error",
                "Surface cannot be created because of an exception:\n\n  " +
                errorMessage + "\n\nPlease select a different surface type.");
            // if suface change was initialized by the GUI this should ensure its
            // consistency
            emit surfaceTypeChanged(m_surfaceType);
            return;
        }
        // end Surface factory

        m_surfaceType = surfaceType;
        surface->setPeakLabelPrecision(peakLabelPrecision);
        surface->setShowPeakRowsFlag(showPeakRow);
        surface->setShowPeakLabelsFlag(showPeakLabels);
        // set new surface
        setSurface(surface);

        // init tabs with new surface
        foreach (InstrumentWindowTab *tab, m_tabs) {
            tab->initSurface();
        }

        // connect(surface,SIGNAL(multipleDetectorsSelected(QList<int>&)),this,SLOT(multipleDetectorsSelected(QList<int>&)));
        connect(surface, SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),
                this, SIGNAL(execMantidAlgorithm(Mantid::API::IAlgorithm_sptr)));
        connect(surface, SIGNAL(updateInfoText()), this, SLOT(updateInfoText()),
                Qt::QueuedConnection);
        QApplication::restoreOverrideCursor();
    }