15#include <Poco/NObserver.h>
34 API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_delete_observer);
37 API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_replace_observer);
43 API::AnalysisDataService::Instance().notificationCenter.addObserver(
m_delete_observer);
50 API::AnalysisDataService::Instance().notificationCenter.addObserver(
m_replace_observer);
79 : m_dimensions(), m_originalWorkspaces(), m_origin(), m_transforms_FromOriginal(), m_transforms_ToOriginal(),
89 m_dimensions = std::vector<std::shared_ptr<IMDDimension>>{};
99 std::vector<Mantid::Geometry::IMDDimension_sptr> dimensions;
100 for (
size_t d = 0;
d < other.getNumDims();
d++) {
102 auto dim = std::make_shared<MDHistoDimension>(other.getDimension(
d).get());
103 dimensions.emplace_back(dim);
108 std::vector<CoordTransform_const_sptr>::const_iterator it;
109 for (it = other.m_transforms_FromOriginal.begin(); it != other.m_transforms_FromOriginal.end(); ++it) {
116 for (it = other.m_transforms_ToOriginal.begin(); it != other.m_transforms_ToOriginal.end(); ++it) {
126 for (
size_t i = 0; i < other.m_originalWorkspaces.size(); i++)
170 [](
const auto &dimension) { return !dimension->getIsIntegrated(); });
180 throw std::runtime_error(
"Workspace does not have a dimension at that index.");
190 auto dimension = std::find_if(
192 [&
id](
const std::shared_ptr<const Mantid::Geometry::IMDDimension> &dim) { return dim->getDimensionId() == id; });
196 throw std::invalid_argument(
"Dimension tagged " +
id +
" was not found in the Workspace");
207 [](
const auto &dimension) { return !dimension->getIsIntegrated(); });
208 return vecCollapsedDimensions;
214 std::vector<coord_t> out;
216 out.emplace_back(this->getDimension(
d)->getBinWidth());
229 [&
name](
const auto &dimension) { return dimension->getName() == name; });
233 throw std::runtime_error(
"Dimension named '" +
name +
"' was not found in the IMDWorkspace.");
245 [&
id](
const auto &dimension) { return dimension->getDimensionId() == id; });
249 throw std::runtime_error(
"Dimension with id '" +
id +
"' was not found in the IMDWorkspace.");
263 m_dimensions.emplace_back(std::shared_ptr<Mantid::Geometry::IMDDimension>(dim));
270 throw std::runtime_error(
"Workspace does not have any dimensions!");
277 throw std::runtime_error(
"Workspace does not have a Y dimension.");
284 throw std::runtime_error(
"Workspace does not have a Z dimension.");
291 throw std::runtime_error(
"Workspace does not have a T dimension.");
303 throw std::invalid_argument(
"getBasisVector(): invalid index");
314 throw std::invalid_argument(
"getBasisVector(): invalid index");
325 throw std::invalid_argument(
"getBasisVector(): invalid index");
363 throw std::runtime_error(
"MDGeometry::getOriginalWorkspace() invalid index.");
401 throw std::invalid_argument(
"MDGeometry::transformDimensions(): "
402 "scaling.size() must be equal to number of "
405 throw std::invalid_argument(
"MDGeometry::transformDimensions(): "
406 "offset.size() must be equal to number of "
413 dim->setRange(dim->getNBins(), min, max);
415 dim->setRange(dim->getNBins(), max, min);
436 if (original == deleted) {
457 if (original == replaced) {
478 throw std::runtime_error(
"MDGeometry::getTransformFromOriginal(): invalid index.");
514 throw std::runtime_error(
"MDGeometry::getTransformFromOriginal(): invalid index.");
544 const size_t nDimensions = this->
getNumDims();
545 for (
size_t i = 0; i < nDimensions; i++) {
549 if (nDimensions > 0) {
552 if (nDimensions > 1) {
555 if (nDimensions > 2) {
558 if (nDimensions > 3) {
562 return xmlBuilder.
create();
std::map< DeltaEMode::Type, std::string > index
std::vector< T > const * vec
MDGeometryNotificationHelper(MDGeometry &parent)
void watchForWorkspaceReplace()
~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()
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,...