/** * 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(); }
/** 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; } }