15#include <Poco/NObserver.h>
34 API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_delete_observer);
37 API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_replace_observer);
47 API::AnalysisDataService::Instance().notificationCenter.addObserver(
m_delete_observer);
54 API::AnalysisDataService::Instance().notificationCenter.addObserver(
m_replace_observer);
83 : m_dimensions(), m_originalWorkspaces(), m_origin(), m_transforms_FromOriginal(), m_transforms_ToOriginal(),
93 m_dimensions = std::vector<std::shared_ptr<IMDDimension>>{};
103 std::vector<Mantid::Geometry::IMDDimension_sptr> dimensions;
104 for (
size_t d = 0;
d < other.getNumDims();
d++) {
106 auto dim = std::make_shared<MDHistoDimension>(other.getDimension(
d).get());
107 dimensions.emplace_back(dim);
112 std::vector<CoordTransform_const_sptr>::const_iterator it;
113 for (it = other.m_transforms_FromOriginal.begin(); it != other.m_transforms_FromOriginal.end(); ++it) {
120 for (it = other.m_transforms_ToOriginal.begin(); it != other.m_transforms_ToOriginal.end(); ++it) {
130 for (
size_t i = 0; i < other.m_originalWorkspaces.size(); i++)
174 [](
const auto &dimension) { return !dimension->getIsIntegrated(); });
184 throw std::runtime_error(
"Workspace does not have a dimension at that index.");
194 auto dimension = std::find_if(
196 [&
id](
const std::shared_ptr<const Mantid::Geometry::IMDDimension> &dim) { return dim->getDimensionId() == id; });
200 throw std::invalid_argument(
"Dimension tagged " +
id +
" was not found in the Workspace");
211 [](
const auto &dimension) { return !dimension->getIsIntegrated(); });
212 return vecCollapsedDimensions;
218 std::vector<coord_t> out;
220 out.emplace_back(this->getDimension(
d)->getBinWidth());
233 [&
name](
const auto &dimension) { return dimension->getName() == name; });
237 throw std::runtime_error(
"Dimension named '" +
name +
"' was not found in the IMDWorkspace.");
249 [&
id](
const auto &dimension) { return dimension->getDimensionId() == id; });
253 throw std::runtime_error(
"Dimension with id '" +
id +
"' was not found in the IMDWorkspace.");
267 m_dimensions.emplace_back(std::shared_ptr<Mantid::Geometry::IMDDimension>(dim));
274 throw std::runtime_error(
"Workspace does not have any dimensions!");
281 throw std::runtime_error(
"Workspace does not have a Y dimension.");
288 throw std::runtime_error(
"Workspace does not have a Z dimension.");
295 throw std::runtime_error(
"Workspace does not have a T dimension.");
307 throw std::invalid_argument(
"getBasisVector(): invalid index");
318 throw std::invalid_argument(
"getBasisVector(): invalid index");
329 throw std::invalid_argument(
"getBasisVector(): invalid index");
367 throw std::runtime_error(
"MDGeometry::getOriginalWorkspace() invalid index.");
405 throw std::invalid_argument(
"MDGeometry::transformDimensions(): "
406 "scaling.size() must be equal to number of "
409 throw std::invalid_argument(
"MDGeometry::transformDimensions(): "
410 "offset.size() must be equal to number of "
417 dim->setRange(dim->getNBins(), min, max);
419 dim->setRange(dim->getNBins(), max, min);
440 if (original == deleted) {
461 if (original == replaced) {
482 throw std::runtime_error(
"MDGeometry::getTransformFromOriginal(): invalid index.");
518 throw std::runtime_error(
"MDGeometry::getTransformFromOriginal(): invalid index.");
548 const size_t nDimensions = this->
getNumDims();
549 for (
size_t i = 0; i < nDimensions; i++) {
553 if (nDimensions > 0) {
556 if (nDimensions > 1) {
559 if (nDimensions > 2) {
562 if (nDimensions > 3) {
566 return xmlBuilder.
create();
std::map< DeltaEMode::Type, std::string > index
std::vector< T > const * vec
MDGeometryNotificationHelper(MDGeometry &parent)
void watchForWorkspaceReplace()
MDGeometryNotificationHelper & operator=(const MDGeometryNotificationHelper &)=delete
~MDGeometryNotificationHelper()
Poco::NObserver< MDGeometryNotificationHelper, WorkspacePreDeleteNotification > m_delete_observer
Poco delete notification observer object.
void deleteNotificationReceived(Mantid::API::WorkspacePreDeleteNotification_ptr notice)
bool m_observingDelete
Set to True when the m_delete_observer is observing workspace deletions.
Poco::NObserver< MDGeometryNotificationHelper, WorkspaceBeforeReplaceNotification > m_replace_observer
void watchForWorkspaceDeletions()
MDGeometryNotificationHelper(const MDGeometryNotificationHelper &)=delete
void replaceNotificationReceived(Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice)
Describes the geometry (i.e.
Kernel::DblMatrix m_Wtransf
the matrix which transforms momentums from orthogonal Q-system to Orthogonal HKL or non-orthogonal HK...
Mantid::API::CoordTransform const * getTransformFromOriginal(size_t index=0) const
Get the Coordinate Transformation that goes from the original workspace to this workspace's coordinat...
void initGeometry(const std::vector< std::shared_ptr< Geometry::IMDDimension > > &dimensions)
Initialize the geometry.
std::shared_ptr< const Mantid::Geometry::IMDDimension > getTDimension() const
Get the t-dimension mapping.
std::vector< Mantid::Kernel::VMD > m_basisVectors
Vector of the basis vector (in the original workspace) for each dimension of this workspace.
virtual ~MDGeometry()
Destructor.
size_t getNumberTransformsToOriginal() const
Get the number of transforms defined to the original coordinate system.
std::vector< std::shared_ptr< const Mantid::API::CoordTransform > > m_transforms_FromOriginal
Coordinate Transformation that goes from the original workspace to this workspace's coordinates.
Mantid::Kernel::VMD m_origin
Vector of the origin (in the original workspace) that corresponds to 0,0,0... in this workspace.
bool allBasisNormalized() const
virtual std::shared_ptr< const Mantid::Geometry::IMDDimension > getDimension(size_t index) const
Get a dimension.
void addDimension(const std::shared_ptr< Mantid::Geometry::IMDDimension > &dim)
Add a dimension.
void replaceNotificationReceived(const std::shared_ptr< const Workspace > &deleted)
Function called when observer detects a workspace is replaced.
std::vector< std::shared_ptr< const Geometry::IMDDimension > > getNonIntegratedDimensions() const
Get non-collapsed dimensions.
void clearTransforms()
Clear transforms.
void setOriginalWorkspace(std::shared_ptr< Workspace > ws, size_t index=0)
Set the "original" workspace (the workspace that was the source for a binned MDWorkspace).
size_t getDimensionIndexById(const std::string &id) const
Get the index of the dimension that matches the ID given.
virtual std::shared_ptr< const Mantid::Geometry::IMDDimension > getDimensionWithId(std::string id) const
Get a dimension.
size_t numOriginalWorkspaces() const
void setBasisVector(size_t index, const Mantid::Kernel::VMD &vec)
Set the basis vector (in the original workspace) for a dimension of this workspace.
std::vector< std::shared_ptr< Geometry::IMDDimension > > m_dimensions
Vector of the dimensions used, in the order X Y Z t, etc.
virtual size_t getNumDims() const
void transformDimensions(std::vector< double > const &scaling, std::vector< double > const &offset)
Transform the dimensions contained in this geometry x' = x*scaling + offset.
void clearOriginalWorkspaces()
Clear original workspaces.
virtual size_t getNumNonIntegratedDims() const
std::vector< std::shared_ptr< const Mantid::API::CoordTransform > > m_transforms_ToOriginal
Coordinate Transformation that goes from this workspace's coordinates to the original workspace coord...
Mantid::API::CoordTransform const * getTransformToOriginal(size_t index=0) const
Get the Coordinate Transformation that goes from THIS workspace's coordinates to the ORIGINAL workspa...
bool hasOriginalWorkspace(size_t index=0) const
void setTransformFromOriginal(Mantid::API::CoordTransform *transform, size_t index=0)
Sets the Coordinate Transformation that goes from the original workspace to this workspace's coordina...
virtual std::vector< coord_t > estimateResolution() const
void setTransformToOriginal(Mantid::API::CoordTransform *transform, size_t index=0)
Sets the Coordinate Transformation that goes from THIS workspace's coordinates to the ORIGINAL worksp...
std::string getGeometryXML() const
std::shared_ptr< Workspace > getOriginalWorkspace(size_t index=0) const
Get the "original" workspace (the workspace that was the source for a binned MDWorkspace).
Mantid::Kernel::VMD & getBasisVector(size_t index)
Get the basis vector (in the original workspace) for a dimension of this workspace.
MDGeometry & operator=(const MDGeometry &other)
size_t getDimensionIndexByName(const std::string &name) const
Get the index of the dimension that matches the name given.
std::shared_ptr< const Mantid::Geometry::IMDDimension > getXDimension() const
Get the x-dimension mapping.
std::vector< std::shared_ptr< Workspace > > m_originalWorkspaces
Pointer to the original workspace(s), if this workspace is a coordinate transformation from an origin...
size_t getNumberTransformsFromOriginal() const
Get the number of transforms defined from the original coordinate system.
void deleteNotificationReceived(const std::shared_ptr< const Workspace > &replaced)
Function called when observer objects recieves a notification.
std::shared_ptr< const Mantid::Geometry::IMDDimension > getYDimension() const
Get the y-dimension mapping.
std::shared_ptr< const Mantid::Geometry::IMDDimension > getZDimension() const
Get the z-dimension mapping.
std::unique_ptr< MDGeometryNotificationHelper > m_notificationHelper
Helper that deals with notifications and observing the ADS.
The class describes one dimension of multidimensional dataset representing an orthogonal dimension an...
bool addXDimension(const IMDDimension_const_sptr &dimension) const
Add x dimension.
bool addZDimension(const IMDDimension_const_sptr &dimension) const
Add z dimension.
bool addYDimension(const IMDDimension_const_sptr &dimension) const
Add y dimension.
bool addTDimension(const IMDDimension_const_sptr &dimension) const
Add t dimension.
const std::string & create() const
Create the xml.
bool addOrdinaryDimension(IMDDimension_const_sptr dimensionToAdd) const
Add a dimension that is neither considered x, y, z or t.
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PreDeleteNotification > & WorkspacePreDeleteNotification_ptr
std::shared_ptr< const CoordTransform > CoordTransform_const_sptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::BeforeReplaceNotification > & WorkspaceBeforeReplaceNotification_ptr
std::shared_ptr< IMDDimension > IMDDimension_sptr
Shared Pointer for IMDDimension. Frequently used type in framework.
std::vector< IMDDimension_const_sptr > VecIMDDimension_const_sptr
Vector of constant shared pointers to IMDDimensions.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...