예제 #1
0
void UnwrappedSphere::rotate(const UnwrappedDetector &udet,
                             Mantid::Kernel::Quat &R) const {
  // rotation from the global axes to those where
  // the z axis points to the detector
  Mantid::Kernel::Quat R1;
  // direction in which to look: from sample to detector
  Mantid::Kernel::V3D eye;
  eye = m_pos - udet.detector->getPos();
  if (!eye.nullVector()) {
    InstrumentActor::rotateToLookAt(eye, m_zaxis, R1);
  }
  // add detector's own rotation
  R = R1 * udet.detector->getRotation();
}
예제 #2
0
void UnwrappedCylinder::rotate(const UnwrappedDetector &udet,
                               Mantid::Kernel::Quat &R) const {
  // direction in which to look
  Mantid::Kernel::V3D eye;
  const auto &componentInfo = m_instrActor->componentInfo();
  // rotation from the global axes to those where
  // the z axis points to the detector
  Mantid::Kernel::Quat R1;
  eye = m_pos - componentInfo.position(udet.detIndex);
  if (!eye.nullVector()) {
    // eye must point towards the detector and be perpendicular to the
    // cylinder's axis
    Mantid::Kernel::V3D up = m_zaxis;
    up.normalize();
    eye = eye - up * eye.scalar_prod(up);
    if (!eye.nullVector()) {
      eye.normalize();
      InstrumentActor::rotateToLookAt(eye, up, R1);
    }
  }
  // add detector's own rotation
  R = R1 * componentInfo.rotation(udet.detIndex);
}
예제 #3
0
/**
 * Calculate a rotation to look in a particular direction.
 *
 * @param eye :: A direction to look in
 * @param up :: A vector showing the 'up' direction after the rotation. It doesn't have to be normal to eye
 *   just non-collinear. If up is collinear to eye the actual 'up' direction is undefined.
 * @param R :: The result rotation.
 */
void InstrumentActor::rotateToLookAt(const Mantid::Kernel::V3D &eye, const Mantid::Kernel::V3D &up, Mantid::Kernel::Quat &R)
{
    if ( eye.nullVector() )
    {
        throw std::runtime_error("The eye vector is null in InstrumentActor::rotateToLookAt.");
    }

    // Basis vectors of the OpenGL reference frame. Z points into the screen, Y points up.
    const Mantid::Kernel::V3D X(1,0,0);
    const Mantid::Kernel::V3D Y(0,1,0);
    const Mantid::Kernel::V3D Z(0,0,1);

    Mantid::Kernel::V3D x,y,z;
    z = eye;
    z.normalize();
    y = up;
    x = y.cross_prod(z);
    if (x.nullVector())
    {
        // up || eye
        if ( z.X() != 0.0 )
        {
            x.setY(1.0);
        }
        else if ( z.Y() != 0.0 )
        {
            x.setZ(1.0);
        }
        else
        {
            x.setX(1.0);
        }
    }
    x.normalize();
    y = z.cross_prod(x);

    BasisRotation(x,y,z,X,Y,Z,R);
}