diff --git a/Code/Mantid/Framework/DataHandling/src/MoveInstrumentComponent.cpp b/Code/Mantid/Framework/DataHandling/src/MoveInstrumentComponent.cpp index eea09c89a231db26170c29241dcfe9d619c706cf..2f8e8db6045c9ea59f6a7b4d5a98a29855060de0 100644 --- a/Code/Mantid/Framework/DataHandling/src/MoveInstrumentComponent.cpp +++ b/Code/Mantid/Framework/DataHandling/src/MoveInstrumentComponent.cpp @@ -11,6 +11,7 @@ The relative position will be applied to the current position, so applying this #include "MantidDataHandling/MoveInstrumentComponent.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/Exception.h" +#include "MantidGeometry/Instrument/ComponentHelper.h" namespace Mantid { @@ -69,7 +70,7 @@ void MoveInstrumentComponent::exec() const double X = getProperty("X"); const double Y = getProperty("Y"); const double Z = getProperty("Z"); - const bool RelativePosition = getProperty("RelativePosition"); + const bool relativePosition = getProperty("RelativePosition"); // Get the ParameterMap reference before the instrument so that // we avoid a copy @@ -106,35 +107,11 @@ void MoveInstrumentComponent::exec() throw std::invalid_argument("DetectorID or ComponentName must be given."); } - V3D Pos;// New relative position - // First set it to the new absolute position - if (RelativePosition) - { - Pos = comp->getPos() + V3D(X,Y,Z); - } - else - { - Pos = V3D(X,Y,Z); - } - - // Then find the corresponding relative position - boost::shared_ptr<const IComponent> parent = comp->getParent(); - if (parent) - { - Pos -= parent->getPos(); - Quat rot = parent->getRelativeRot(); - rot.inverse(); - rot.rotate(Pos); - } - boost::shared_ptr<const IComponent>grandparent = parent->getParent(); - if (grandparent) - { - Quat rot = grandparent->getRelativeRot(); - rot.inverse(); - rot.rotate(Pos); - } - // Add a parameter for the new position - pmap.addV3D(comp.get(), "pos", Pos); + // Do the move + using namespace Geometry::ComponentHelper; + TransformType positionType = Absolute; + if(relativePosition) positionType = Relative; + Geometry::ComponentHelper::moveComponent(*comp, pmap, V3D(X,Y,Z), positionType); return; } diff --git a/Code/Mantid/Framework/DataHandling/src/RotateInstrumentComponent.cpp b/Code/Mantid/Framework/DataHandling/src/RotateInstrumentComponent.cpp index c358bca4ea80befac91db0dd00a4a328e4c5aa01..1fc21fbae5cbd1a759ec165d60fd75bb9e93262d 100644 --- a/Code/Mantid/Framework/DataHandling/src/RotateInstrumentComponent.cpp +++ b/Code/Mantid/Framework/DataHandling/src/RotateInstrumentComponent.cpp @@ -11,6 +11,7 @@ RotateInstrumentComponent rotates a component around an axis of rotation by an a #include "MantidDataHandling/RotateInstrumentComponent.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/Exception.h" +#include "MantidGeometry/Instrument/ComponentHelper.h" namespace Mantid { @@ -64,7 +65,7 @@ void RotateInstrumentComponent::exec() const double Y = getProperty("Y"); const double Z = getProperty("Z"); const double angle = getProperty("Angle"); - const bool RelativeRotation = getProperty("RelativeRotation"); + const bool relativeRotation = getProperty("RelativeRotation"); if (X + Y + Z == 0.0) throw std::invalid_argument("The rotation axis must not be a zero vector"); @@ -103,30 +104,11 @@ void RotateInstrumentComponent::exec() throw std::invalid_argument("DetectorID or ComponentName must be given."); } - // First set new relative or absolute rotation - Quat Rot; - if (RelativeRotation) - { - Quat Rot0 = comp->getRelativeRot(); - Rot = Rot0 * Quat(angle,V3D(X,Y,Z)); - } - else - { - Rot = Quat(angle,V3D(X,Y,Z)); - // Then find the corresponding relative position - boost::shared_ptr<const IComponent> parent = comp->getParent(); - if (parent) - { - Quat rot0 = parent->getRelativeRot(); - rot0.inverse(); - Rot = Rot * rot0; - } - } - - // Add a parameter for the new rotation - pmap.addQuat(comp.get(), "rot", Rot); - - return; + // Do the rotation + using namespace Geometry::ComponentHelper; + TransformType rotType = Absolute; + if(relativeRotation) rotType = Relative; + Geometry::ComponentHelper::rotateComponent(*comp, pmap, Quat(angle,V3D(X,Y,Z)), rotType); } } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/src/SetScalingPSD.cpp b/Code/Mantid/Framework/DataHandling/src/SetScalingPSD.cpp index 443aea6d06214b2e0dad9798254bacd6caac3790..9231e3b64d05a014eb1292cda54504640b256da8 100644 --- a/Code/Mantid/Framework/DataHandling/src/SetScalingPSD.cpp +++ b/Code/Mantid/Framework/DataHandling/src/SetScalingPSD.cpp @@ -57,6 +57,7 @@ None #include "MantidDataHandling/SetScalingPSD.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" +#include "MantidGeometry/Instrument/ComponentHelper.h" #include "MantidAPI/FileProperty.h" #include "MantidAPI/WorkspaceValidators.h" #include <cmath> @@ -326,6 +327,7 @@ void SetScalingPSD::movePos(API::MatrixWorkspace_sptr& WS, std::map<int,Kernel:: * @param scaleMap :: A map of integer detectorID and corresponding scaling (in Y) */ std::map<int,Kernel::V3D>::iterator iter = posMap.begin(); + Geometry::ParameterMap& pmap = WS->instrumentParameters(); boost::shared_ptr<const Instrument> inst = WS->getInstrument(); boost::shared_ptr<const IComponent> comp; @@ -343,7 +345,6 @@ void SetScalingPSD::movePos(API::MatrixWorkspace_sptr& WS, std::map<int,Kernel:: // loop over detector (IComps) for(size_t id=0;id<m_vectDet.size();id++) { - V3D Pos,shift;// New relative position comp = m_vectDet[id]; boost::shared_ptr<const IDetector> det = boost::dynamic_pointer_cast<const IDetector>(comp); int idet=0; @@ -351,23 +352,7 @@ void SetScalingPSD::movePos(API::MatrixWorkspace_sptr& WS, std::map<int,Kernel:: iter=posMap.find(idet); // check if we have a shift if(iter==posMap.end()) continue; - shift=iter->second; - // First set it to the new absolute position (code from MoveInstrument) - Pos = comp->getPos() + shift; - - // Then find the corresponding relative position - boost::shared_ptr<const IComponent> parent = comp->getParent(); - if (parent) - { - Pos -= parent->getPos(); - Quat rot = parent->getRelativeRot(); - rot.inverse(); - rot.rotate(Pos); - } - - //Need to get the address to the base instrument component - Geometry::ParameterMap& pmap = WS->instrumentParameters(); - pmap.addV3D(comp.get(), "pos", Pos); + Geometry::ComponentHelper::moveComponent(*det, pmap, iter->second, Geometry::ComponentHelper::Relative); // Set the "sca" instrument parameter std::map<int,double>::iterator it=scaleMap.find(idet); diff --git a/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp b/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp index 251173fd4bc11d2326288b32ad4983bea16e00f0..b9df0a998c8bfd368f90da42749053e43190d5b8 100644 --- a/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp +++ b/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp @@ -17,6 +17,7 @@ It is assumed that the positions specified in the raw file are all with respect #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/SpectraDetectorMap.h" #include "MantidGeometry/Instrument.h" +#include "MantidGeometry/Instrument/ComponentHelper.h" #include "MantidNexusCPP/NeXusFile.hpp" #include "MantidNexusCPP/NeXusException.hpp" #include "LoadRaw/isisraw2.h" @@ -401,8 +402,6 @@ namespace Mantid const float theta, const float phi) { Geometry::ParameterMap & pmap = m_workspace->instrumentParameters(); - V3D parentPos; - if( det->getParent() ) parentPos = det->getParent()->getPos(); Kernel::V3D pos; if (!m_ignorePhi) { @@ -414,12 +413,7 @@ namespace Mantid det->getPos().getSpherical(r,t,p); pos.spherical(l2, theta, p); } - // Set new relative position - Kernel::V3D r = pos-parentPos; - Kernel::Quat q = det->getParent()->getRotation(); - q.inverse(); - q.rotate(r); - pmap.addV3D(det.get(), "pos", r); + Geometry::ComponentHelper::moveComponent(*det, pmap, pos, Geometry::ComponentHelper::Absolute); } } // namespace DataHandling