Beispiel #1
0
void SliceMDHisto::cutData(Mantid::API::IMDHistoWorkspace_sptr inWS,
                           Mantid::API::IMDHistoWorkspace_sptr outWS,
                           Mantid::coord_t *sourceDim,
                           Mantid::coord_t *targetDim, std::vector<int> start,
                           std::vector<int> end, unsigned int dim) {
  int length;

  boost::shared_ptr<const IMDDimension> inDim = inWS->getDimension(dim);
  boost::shared_ptr<const IMDDimension> outDim = outWS->getDimension(dim);
  length = end[dim] - start[dim];
  if (dim == m_rank - 1) {
    MDHistoWorkspace_sptr outWSS =
        boost::dynamic_pointer_cast<MDHistoWorkspace>(outWS);
    for (int i = 0; i < length; i++) {
      sourceDim[dim] = inDim->getX(start[dim] + i);
      signal_t val = inWS->getSignalAtCoord(
          sourceDim, static_cast<Mantid::API::MDNormalization>(0));
      targetDim[dim] = outDim->getX(i);
      size_t idx = outWSS->getLinearIndexAtCoord(targetDim);
      outWS->setSignalAt(idx, val);
      outWS->setErrorSquaredAt(idx, val);
    }
  } else {
    for (int i = 0; i < length; i++) {
      sourceDim[dim] = inDim->getX(start[dim] + i);
      targetDim[dim] = outDim->getX(i);
      cutData(inWS, outWS, sourceDim, targetDim, start, end, dim + 1);
    }
  }
}
void MDHistoToWorkspace2D::copyMetaData(
    Mantid::API::IMDHistoWorkspace_sptr inWS,
    Mantid::DataObjects::Workspace2D_sptr outWS) {
  if (inWS->getNumExperimentInfo() > 0) {
    ExperimentInfo_sptr info = inWS->getExperimentInfo(0);
    outWS->copyExperimentInfoFrom(info.get());
  }
  outWS->setTitle(inWS->getTitle());
}
Beispiel #3
0
void SliceMDHisto::copyMetaData(Mantid::API::IMDHistoWorkspace_sptr inws,
                                Mantid::API::IMDHistoWorkspace_sptr outws) {
  outws->setTitle(inws->getTitle());
  ExperimentInfo_sptr info;

  if (inws->getNumExperimentInfo() > 0) {
    info = inws->getExperimentInfo(0);
    outws->addExperimentInfo(info);
  }
}
/**
 * @brief MDHWInMemoryLoadingPresenter::transposeWs
 *
 * vtkDataSets are usually provided in 3D, trying to create these where one of
 *those dimensions
 * might be integrated out leads to empty datasets. To avoid this we reorder the
 *dimensions in our workspace
 * prior to visualisation by transposing if if needed.
 *
 * @param inHistoWs : An input workspace that may integrated dimensions
 *anywhere.
 * @param outCachedHistoWs : Cached histo workspace. To write to if needed.
 * @return A workspace that can be directly rendered from. Integrated dimensions
 *are always last.
 */
void MDHWLoadingPresenter::transposeWs(
    Mantid::API::IMDHistoWorkspace_sptr &inHistoWs,
    Mantid::API::IMDHistoWorkspace_sptr &outCachedHistoWs) {
  using namespace Mantid::API;

  if (!outCachedHistoWs) {
    /*
     Construct dimension indexes list for transpose. We do this by forcing
     integrated
     dimensions to be the last in the list. All other orderings are kept.
     */
    std::vector<int> integratedDims;
    std::vector<int> nonIntegratedDims;
    for (int i = 0; i < int(inHistoWs->getNumDims()); ++i) {
      auto dim = inHistoWs->getDimension(i);
      if (dim->getIsIntegrated()) {
        integratedDims.push_back(i);
      } else {
        nonIntegratedDims.push_back(i);
      }
    }

    std::vector<int> orderedDims = nonIntegratedDims;
    orderedDims.insert(orderedDims.end(), integratedDims.begin(),
                       integratedDims.end());

    /*
     If there has been any reordering above, then the dimension indexes will
     no longer be sorted. We use that to determine if we can avoid transposing
     the workspace.
     */
    if (!std::is_sorted(orderedDims.begin(), orderedDims.end())) {
      IAlgorithm_sptr alg = AlgorithmManager::Instance().create("TransposeMD");
      alg->setChild(true);
      alg->initialize();
      alg->setProperty("InputWorkspace", inHistoWs);
      alg->setPropertyValue("OutputWorkspace", "dummy");
      alg->setProperty("Axes", orderedDims);
      alg->execute();
      IMDHistoWorkspace_sptr visualHistoWs =
          alg->getProperty("OutputWorkspace");
      outCachedHistoWs = visualHistoWs;
    } else {
      // No need to transpose anything.
      outCachedHistoWs = inHistoWs;
    }
  }
}
     /*
    Extract the geometry and function information 
    @param histoWs : histogram workspace to get the information from.
    */
    void MDHWLoadingPresenter::extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs)
    {
      using namespace Mantid::Geometry;
      MDGeometryBuilderXML<NoDimensionPolicy> refresh;
      xmlBuilder= refresh; //Reassign.
      std::vector<IMDDimension_sptr> dimensions;
      size_t nDimensions = histoWs->getNumDims();
      for (size_t d=0; d<nDimensions; d++)
      {
        IMDDimension_const_sptr inDim = histoWs->getDimension(d);
        coord_t min = inDim->getMinimum();
        coord_t max = inDim->getMaximum();
        if (min > max)
        {
          min = 0.0;
          max = 1.0;
        }
        //std::cout << "dim " << d << min << " to " <<  max << std::endl;
        axisLabels.push_back(makeAxisTitle(inDim));
        MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getUnits(), min, max, inDim->getNBins()));
        dimensions.push_back(dim);
      }

      //Configuring the geometry xml builder allows the object panel associated with this reader to later
      //determine how to display all geometry related properties.
      if(nDimensions > 0)
      {
        xmlBuilder.addXDimension( dimensions[0] );
      }
      if(nDimensions > 1)
      {
        xmlBuilder.addYDimension( dimensions[1] );
      }
      if(nDimensions > 2)
      {
        xmlBuilder.addZDimension( dimensions[2]  );
      }
      if(nDimensions > 3)
      {
        tDimension = dimensions[3];
        xmlBuilder.addTDimension(tDimension);
      }
      m_isSetup = true;
    }