Exemplo n.º 1
0
/**
 * This function is responsible for opening the given cut in SliceViewer.
 * It will gather all of the necessary information and create an XML
 * representation of the current dataset and cut parameters. That will then
 * be handed to the SliceViewer.
 * @param axisIndex the index of the slice to be opened in SliceViewer
 * @param sliceOffsetOnAxis position of the slice along given axis
 */
void MultiSliceView::showCutInSliceViewer(int axisIndex,
                                          double sliceOffsetOnAxis) {
  // Get the associated workspace name
  QString wsName = this->getWorkspaceName();

  // Have to jump through some hoops since a rebinner could be used.
  pqServerManagerModel *smModel =
      pqApplicationCore::instance()->getServerManagerModel();
  QList<pqPipelineSource *> srcs = smModel->findItems<pqPipelineSource *>();
  pqPipelineSource *src1 = nullptr;
  pqPipelineSource *src2 = nullptr;
  foreach (pqPipelineSource *src, srcs) {
    const QString name(src->getProxy()->GetXMLName());

    if (name.contains("ScaleWorkspace")) {
      src2 = src;
    }
  }

  src1 = smModel->getItemAtIndex<pqPipelineSource *>(0);

  // Get the current dataset characteristics
  const char *inGeomXML =
      vtkSMPropertyHelper(src1->getProxy(), "InputGeometryXML").GetAsString();
  // Check for timesteps and insert the value into the XML if necessary
  std::string geomXML;
  if (this->srcHasTimeSteps(src1)) {
    GeometryParser parser(inGeomXML);
    geomXML = parser.addTDimValue(this->getCurrentTimeStep());
  } else {
    geomXML = std::string(inGeomXML);
  }

  if (src2) {
    // Need to see if scaling is applied to axis
    QString scalingProperty("Scaling Factor");
    switch (axisIndex) {
    case 0:
      scalingProperty.prepend("X ");
      break;
    case 1:
      scalingProperty.prepend("Y ");
      break;
    case 2:
      scalingProperty.prepend("Z ");
      break;
    default:
      break;
    }

    std::vector<double> scaling =
        vtkSMPropertyHelper(src2->getProxy(),
                            scalingProperty.toLatin1().constData(),
                            true).GetDoubleArray();

    if (!scaling.empty()) {
      sliceOffsetOnAxis /= scaling[0];
    }
  }

  // Construct origin vector from orientation vector
  double origin[3] = {0.0, 0.0, 0.0};
  origin[axisIndex] = sliceOffsetOnAxis;

  vtkVector3d sliceNormalsInBasis[3] = {
      {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}};

  // Create the XML holder
  VATES::VatesKnowledgeSerializer rks;
  rks.setWorkspaceName(wsName.toStdString());
  rks.setGeometryXML(geomXML);

  rks.setImplicitFunction(boost::make_shared<MDPlaneImplicitFunction>(
      3, sliceNormalsInBasis[axisIndex].GetData(), origin));
  QString titleAddition = "";

  // Use the WidgetFactory to create the slice viewer window
  SliceViewerWindow *w =
      MantidQt::Factory::WidgetFactory::Instance()->createSliceViewerWindow(
          wsName, titleAddition);
  try {
    // Set the slice points, etc, using the XML definition of the plane function
    w->getSlicer()->openFromXML(QString::fromStdString(rks.createXMLString()));
    w->show();
    this->connect(w->getSlicer(),
                  SIGNAL(changedSlicePoint(Mantid::Kernel::VMD)),
                  SLOT(changedSlicePoint(Mantid::Kernel::VMD)));
  } catch (std::runtime_error &e) {
    QString message =
        "The slice could not be shown because of the following error:\n" +
        QString(e.what());
    QMessageBox::warning(this, tr("MantidPlot"),
                         tr(message.toLatin1().constData()), QMessageBox::Ok,
                         QMessageBox::Ok);
    delete w;
  }
}
Exemplo n.º 2
0
/**
 * This function is responsible for opening the given cut in SliceViewer.
 * It will gather all of the necessary information and create an XML
 * representation of the current dataset and cut parameters. That will then
 * be handed to the SliceViewer.
 * @param axisIndex the index of the slice to be opened in SliceViewer
 * @param sliceOffsetOnAxis position of the slice along given axis
 */
void MultiSliceView::showCutInSliceViewer(int axisIndex,
                                          double sliceOffsetOnAxis)
{
  // Get the associated workspace name
  QString wsName = this->getWorkspaceName();

  // Have to jump through some hoops since a rebinner could be used.
  pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel();
  QList<pqPipelineSource *> srcs = smModel->findItems<pqPipelineSource *>();
  pqPipelineSource *src1 = NULL;
  pqPipelineSource *src2 = NULL;
  foreach (pqPipelineSource *src, srcs)
  {
    const QString name(src->getProxy()->GetXMLName());
    if (name.contains("MDEWRebinningCutter"))
    {
      src1 = src;
    }
    if (name.contains("ScaleWorkspace"))
    {
      src2 = src;
    }
  }
  if (NULL == src1)
  {
    src1 = smModel->getItemAtIndex<pqPipelineSource *>(0);
  }

  // Get the current dataset characteristics
  const char *inGeomXML = vtkSMPropertyHelper(src1->getProxy(),
                                             "InputGeometryXML").GetAsString();
  // Check for timesteps and insert the value into the XML if necessary
  std::string geomXML;
  if ( this->srcHasTimeSteps(src1) )
  {
    GeometryParser parser(inGeomXML);
    geomXML = parser.addTDimValue(this->getCurrentTimeStep());
  }
  else
  {
    geomXML = std::string(inGeomXML);
  }

  if (NULL != src2)
  {
    // Need to see if scaling is applied to axis
    QString scalingProperty("Scaling Factor");
    switch (axisIndex)
    {
    case 0:
      scalingProperty.prepend("X ");
      break;
    case 1:
      scalingProperty.prepend("Y ");
      break;
    case 2:
      scalingProperty.prepend("Z ");
      break;
    default:
      break;
    }

    std::vector<double> scaling = vtkSMPropertyHelper(src2->getProxy(),
                                                      scalingProperty,
                                                      true).GetDoubleArray();

    if (!scaling.empty())
    {
      sliceOffsetOnAxis /= scaling[0];
    }
  }
  const double *orient = this->mainView->GetSliceNormal(axisIndex);

  // Construct origin vector from orientation vector
  double origin[3];
  origin[0] = sliceOffsetOnAxis * orient[0];
  origin[1] = sliceOffsetOnAxis * orient[1];
  origin[2] = sliceOffsetOnAxis * orient[2];

  // Create the XML holder
  VATES::RebinningKnowledgeSerializer rks(VATES::LocationNotRequired);
  rks.setWorkspaceName(wsName.toStdString());
  rks.setGeometryXML(geomXML);

  MDImplicitFunction_sptr impplane(new MDPlaneImplicitFunction(3, orient,
                                                               origin));
  rks.setImplicitFunction(impplane);
  QString titleAddition = "";

  // Use the WidgetFactory to create the slice viewer window
  SliceViewerWindow *w = MantidQt::Factory::WidgetFactory::Instance()->createSliceViewerWindow(wsName, titleAddition);
  try
  {
    // Set the slice points, etc, using the XML definition of the plane function
    w->getSlicer()->openFromXML( QString::fromStdString(rks.createXMLString()) );
    w->show();
  }
  catch (std::runtime_error & e)
  {
    QMessageBox::warning(this, tr("MantidPlot"),
                       tr("The slice could not be shown because of the following error:\n"
                          + QString(e.what())),
                       QMessageBox::Ok, QMessageBox::Ok);
    delete w;
  }
}