/** Set the workspace * @param ws :: A shared pointer to a workspace. */ void IFunctionMD::setWorkspace(boost::shared_ptr<const Workspace> ws) { try { IMDWorkspace_const_sptr workspace = boost::dynamic_pointer_cast<const IMDWorkspace>(ws); if (!workspace) { throw std::invalid_argument("Workspace has a wrong type (not a IMDWorkspace)"); } if (m_dimensionIndexMap.empty()) { useAllDimensions(workspace); } m_dimensions.resize(m_dimensionIndexMap.size()); std::map<std::string,size_t>::const_iterator it = m_dimensionIndexMap.begin(); std::map<std::string,size_t>::const_iterator end = m_dimensionIndexMap.end(); for(; it != end; ++it) { boost::shared_ptr<const Mantid::Geometry::IMDDimension> dim = workspace->getDimensionWithId(it->first); if (!dim) { throw std::invalid_argument("Dimension "+it->first+" dos not exist in workspace "+ws->getName()); } m_dimensions[it->second] = dim; } } catch(std::exception&) { throw; } }
/** * This method is called if a function does not call to useDimension at all. * It adds all the dimensions in the workspace in the order they are in in that workspace * then calls init(). */ void IFunctionMD::useAllDimensions(IMDWorkspace_const_sptr workspace) { if (!workspace) { throw std::runtime_error("Method IFunctionMD::useAllDimensions() can only be called after setting the workspace"); } for(size_t i = 0; i < workspace->getNumDims(); ++ i) { useDimension(workspace->getDimension(i)->getDimensionId()); } this->initDimensions(); }
/** * @param g :: The Graph widget which will display the curve * @param distr :: True if this is a distribution, * not applicable here. * @param style :: The graph style to use * @param multipleSpectra :: True if there are multiple spectra, * not applicable here. */ void MantidMDCurve::init(Graph *g, bool distr, GraphOptions::CurveType style, bool multipleSpectra) { UNUSED_ARG(distr); UNUSED_ARG(multipleSpectra); IMDWorkspace_const_sptr ws = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(m_wsName.toStdString())); if (!ws) { std::string message = "Could not extract IMDWorkspace of name: " + m_wsName.toStdString(); throw std::runtime_error(message); } if (ws->getNonIntegratedDimensions().size() != 1) { std::string message = "This plot only applies to MD Workspaces with a " "single expanded dimension"; throw std::invalid_argument(message); } this->setTitle(m_wsName + "-signal"); const bool log = g->isLog(QwtPlot::yLeft); MantidQwtIMDWorkspaceData data(ws, log); setData(data); int lineWidth = 1; MultiLayer *ml = dynamic_cast<MultiLayer *>(g->parent()->parent()->parent()); if (ml && (style == GraphOptions::Unspecified || ml->applicationWindow()->applyCurveStyleToMantid)) { // FIXME: Style HorizontalSteps does NOT seem to be applied applyStyleChoice(style, ml, lineWidth); } else { setStyle(QwtPlotCurve::Lines); } g->insertCurve(this, lineWidth); // set the option to draw all error bars from the global settings if (hasErrorBars()) { setErrorBars(true, g->multiLayer()->applicationWindow()->drawAllErrors); } // Initialise error bar colour to match curve colour m_errorSettings->m_color = pen().color(); m_errorSettings->setWidth(pen().widthF()); connect(g, SIGNAL(axisScaleChanged(int, bool)), this, SLOT(axisScaleChanged(int, bool))); observePostDelete(); connect(this, SIGNAL(resetData(const QString &)), this, SLOT(dataReset(const QString &))); observeAfterReplace(); observeADSClear(); }
/** Automatically choose which coordinate to use as the X axis, * if we selected it to be automatic */ void MantidQwtIMDWorkspaceData::choosePlotAxis() { if (m_plotAxis == MantidQwtIMDWorkspaceData::PlotAuto) { if (m_transform) { // Find the start and end points in the original workspace VMD originalStart = m_transform->applyVMD(m_start); VMD originalEnd = m_transform->applyVMD(m_end); VMD diff = originalEnd - originalStart; // Now we find the dimension with the biggest change double largest = -1e30; // Default to 0 m_currentPlotAxis = 0; IMDWorkspace_const_sptr originalWS = m_originalWorkspace.lock(); bool regularBinnedMDWorkspace = false; if(auto mdew = boost::dynamic_pointer_cast<const Mantid::API::IMDEventWorkspace>(m_workspace)) { Mantid::API::BoxController_const_sptr controller = mdew->getBoxController(); bool atLeastOneDimNotIntegrated = false; for(size_t i = 0; i < mdew->getNumDims(); ++i) { if( mdew->getDimension(i)->getNBins() == controller->getSplitInto(i)) { if(!mdew->getDimension(i)->getIsIntegrated()) { atLeastOneDimNotIntegrated = true; } } } regularBinnedMDWorkspace = atLeastOneDimNotIntegrated; } if(NULL != boost::dynamic_pointer_cast<const Mantid::API::IMDHistoWorkspace>(originalWS) || regularBinnedMDWorkspace) { for (size_t d=0; d<diff.getNumDims(); d++) { if (fabs(diff[d]) > largest || ( originalWS && originalWS->getDimension(m_currentPlotAxis)->getIsIntegrated() ) ) { //Skip over any integrated dimensions if( originalWS && !originalWS->getDimension(d)->getIsIntegrated() ) { largest = fabs(diff[d]); m_currentPlotAxis = int(d); } } } } else { for (size_t d=0; d<diff.getNumDims(); d++) { if (fabs(diff[d]) > largest) { largest = fabs(diff[d]); m_currentPlotAxis = int(d); } } } } else // Drop to distance if the transform does not exist m_currentPlotAxis = MantidQwtIMDWorkspaceData::PlotDistance; } else { // Pass-through the value. m_currentPlotAxis = m_plotAxis; } }