IMDWorkspace.h 6.49 KB
Newer Older
1
2
3
4
5
6
#ifndef MANTID_API_IMDWORKSPACE_H_
#define MANTID_API_IMDWORKSPACE_H_

//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
7
#include <stdint.h>
8
#include "MantidAPI/Workspace.h"
9
#include "MantidGeometry/MDGeometry/IMDDimension.h"
10
#include <vector>
11
#include <stdarg.h>
12
#include "MantidAPI/MDGeometry.h"
13
#include "MantidGeometry/MDGeometry/MDImplicitFunction.h"
14
#include "MantidAPI/IMDWorkspace.h"
15
#include "MantidKernel/SpecialCoordinateSystem.h"
16
#include "MantidAPI/ITableWorkspace_fwd.h"
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace Mantid {

namespace API {

class IMDIterator;

/** Enum describing different ways to normalize the signal
 * in a MDWorkspace.
 */
enum MDNormalization {
  /// Don't normalize = return raw counts
  NoNormalization = 0,
  /// Divide the signal by the volume of the box/bin
  VolumeNormalization = 1,
  /// Divide the signal by the number of events that contributed to it.
  NumEventsNormalization = 2
};

36
static const signal_t MDMaskValue = std::numeric_limits<double>::quiet_NaN();
37

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/** Basic MD Workspace Abstract Class.
 *
 *  This defines the interface that allows one to iterate through several types
 of workspaces:
 *
 *   - The regularly gridded MDHistoWorkspace
 *   - The recursively binned MDEventWorkspace
 *   - The regular (2D) MatrixWorkspace.
 *
 @author Janik Zikovsky
 @date 04/10/2010

 Copyright &copy; 2007-2010 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
 National Laboratory & European Spallation Source

 This file is part of Mantid.

 Mantid is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.

 Mantid is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

 File change history is stored at: <https://github.com/mantidproject/mantid>.
 Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

72
class MANTID_API_DLL IMDWorkspace : public Workspace, public API::MDGeometry {
73
74
public:
  IMDWorkspace();
75
  IMDWorkspace &operator=(const IMDWorkspace &other) = delete;
76

77
78
79
80
81
82
83
84
85
  /**
   * Holds X, Y, E for a line plot
   */
  struct LinePlot {
    std::vector<coord_t> x;
    std::vector<signal_t> y;
    std::vector<signal_t> e;
  };

86
87
88
89
  /// Returns a clone of the workspace
  std::unique_ptr<IMDWorkspace> clone() const {
    return std::unique_ptr<IMDWorkspace>(doClone());
  }
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  /// Get the number of points associated with the workspace.
  /// For MDEvenWorkspace it is the number of events contributing into the
  /// workspace
  /// For regularly gridded workspace (MDHistoWorkspace and MatrixWorkspace), it
  /// is
  /// the number of bins.
  virtual uint64_t getNPoints() const = 0;
  /*** Get the number of events, associated with the workspace
     * For MDEvenWorkspace it is equal to the number of points
     * For regularly gridded workspace (MDHistoWorkspace and MatrixWorkspace),
   * it is the number of contributed non-zero events.
  */
  virtual uint64_t getNEvents() const = 0;

  /// Creates a new iterator pointing to the first cell in the workspace
  virtual std::vector<IMDIterator *> createIterators(
      size_t suggestedNumCores = 1,
107
      Mantid::Geometry::MDImplicitFunction *function = nullptr) const = 0;
108
109
110
111
112
113

  /// Returns the (normalized) signal at a given coordinates
  virtual signal_t
  getSignalAtCoord(const coord_t *coords,
                   const Mantid::API::MDNormalization &normalization) const = 0;

114
  /// Returns the (normalized) signal at a given coordinates or 0 if the value
115
  // is masked, used for plotting
116
117
118
  virtual signal_t getSignalWithMaskAtCoord(
      const coord_t *coords,
      const Mantid::API::MDNormalization &normalization) const = 0;
119

120
  /// Method to generate a line plot through a MD-workspace
121
122
123
  virtual LinePlot getLinePlot(const Mantid::Kernel::VMD &start,
                               const Mantid::Kernel::VMD &end,
                               Mantid::API::MDNormalization normalize) const;
124

125
126
  IMDIterator *createIterator(
      Mantid::Geometry::MDImplicitFunction *function = nullptr) const;
127

128
  std::string getConvention() const;
129
  void setConvention(std::string convention);
130
  std::string changeQConvention();
131

132
133
134
135
  signal_t getSignalAtVMD(const Mantid::Kernel::VMD &coords,
                          const Mantid::API::MDNormalization &normalization =
                              Mantid::API::VolumeNormalization) const;

136
137
138
139
140
  signal_t
  getSignalWithMaskAtVMD(const Mantid::Kernel::VMD &coords,
                         const Mantid::API::MDNormalization &normalization =
                             Mantid::API::VolumeNormalization) const;

141
142
143
144
145
146
147
  /// Setter for the masking region.
  virtual void
  setMDMasking(Mantid::Geometry::MDImplicitFunction *maskingRegion) = 0;

  /// Clear existing masks
  virtual void clearMDMasking() = 0;
  ///
148
  virtual Kernel::SpecialCoordinateSystem
149
150
151
  getSpecialCoordinateSystem() const = 0;
  /// if a workspace was filebacked, this should clear file-based status, delete
  /// file-based information and close related files.
152
  virtual void clearFileBacked(bool /* loadFileContentsToMemory*/) {}
153
154
155
156
157
  /// this is the method to build table workspace from any workspace. It does
  /// not have much sence and may be placed here erroneously
  virtual ITableWorkspace_sptr makeBoxTable(size_t /*start*/, size_t /* num*/) {
    throw Kernel::Exception::NotImplementedError(
        "This method is not generally implemented ");
158
159
  }

Owen Arnold's avatar
Owen Arnold committed
160
161
162
  // Preferred normalization to use for display
  virtual MDNormalization displayNormalization() const;

163
164
165
  // Preferred normalization to use for displaying histo workspaces
  virtual MDNormalization displayNormalizationHisto() const;

166
protected:
167
  /// Protected copy constructor. May be used by childs for cloning.
168
  IMDWorkspace(const IMDWorkspace &) = default;
169

170
  const std::string toString() const override;
171
172

private:
173
  std::string m_convention;
174
  IMDWorkspace *doClone() const override = 0;
175
176
177
178
179
180
181
182
183
};

/// Shared pointer to the IMDWorkspace base class
typedef boost::shared_ptr<IMDWorkspace> IMDWorkspace_sptr;
/// Shared pointer to the IMDWorkspace base class (const version)
typedef boost::shared_ptr<const IMDWorkspace> IMDWorkspace_const_sptr;
}
}
#endif // MANTID_API_IMDWORKSPACE_H_