Пример #1
0
/** Constructor with N-1 vectors on the plane's surface.
 *
 * @param vectors :: vector of N-1 vectors with N dimensions.
 * @param origin :: any point on the plane
 * @param insidePoint :: coordinate of a point that is known to be inside the
 *plane described
 * @throws if the vectors are collinear
 */
MDPlane::MDPlane(const std::vector<Mantid::Kernel::VMD> &vectors,
                 const Mantid::Kernel::VMD &origin,
                 const Mantid::Kernel::VMD &insidePoint) {
  // Get the normal vector by the determinant method
  VMD normal = VMD::getNormalVector(vectors);

  // The dimensionality of the plane
  m_nd = normal.getNumDims();

  // Whew. We have a normal, and a point on the plane. We can construct
  construct(normal, origin);

  // Did we get the wrong sign of the normal?
  if (!this->isPointBounded(insidePoint)) {
    // Flip the normal over
    delete[] this->m_normal;
    for (size_t d = 0; d < normal.getNumDims(); d++)
      normal[d] = -1.0f * normal[d];
    // And re-construct
    construct(normal, origin);
  }
}
/** 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;
  }
}