-
Notifications
You must be signed in to change notification settings - Fork 122
/
UserFunctionMD.h
68 lines (59 loc) · 2.08 KB
/
UserFunctionMD.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IFunctionMD.h"
#include "MantidAPI/ParamFunction.h"
#include "MantidGeometry/muParser_Silent.h"
namespace Mantid {
namespace MDAlgorithms {
/**
A user defined function.
@author Roman Tolchenov, Tessella plc
@date 15/01/2010
*/
class DLLExport UserFunctionMD : virtual public API::IFunctionMD, virtual public API::ParamFunction {
public:
UserFunctionMD();
std::string name() const override { return "UserFunctionMD"; }
std::vector<std::string> getAttributeNames() const override;
bool hasAttribute(const std::string &attName) const override;
Attribute getAttribute(const std::string &attName) const override;
void setAttribute(const std::string &attName, const Attribute &attr) override;
/**
* Defining function's parameters here, ie after the workspace is set and
* the dimensions are known.
*/
void initDimensions() override;
protected:
/**
* Calculate the function value at a point r in the MD workspace
* @param r :: MD workspace iterator with a reference to the current point
*/
double functionMD(const API::IMDIterator &r) const override;
/** Static callback function used by MuParser to initialize variables
implicitly
@param varName :: The name of a new variable
@param pufun :: Pointer to the function
*/
static double *AddVariable(const char *varName, void *pufun);
/**
* Initializes the mu::Parser.
*/
void setFormula();
private:
/// Expression parser
mu::Parser m_parser;
///
mutable std::vector<double> m_vars;
std::vector<std::string> m_varNames;
std::string m_formula;
};
} // namespace MDAlgorithms
} // namespace Mantid