12#include <boost/python/class.hpp>
13#include <boost/python/copy_non_const_reference.hpp>
14#include <boost/python/exec.hpp>
15#include <boost/python/import.hpp>
16#include <boost/python/make_constructor.hpp>
27void setUnit(
Projection &p,
size_t nd,
const std::string &unit) {
33 throw std::runtime_error(
"Invalid unit");
43 object main =
import(
"__main__");
44 object global(
main.attr(
"__dict__"));
46 exec(
"def createWorkspace(proj, OutputWorkspace=None):\n"
47 " '''Create a TableWorkspace using this projection'''\n"
49 " from mantid import api, kernel, AnalysisDataService\n"
50 " ws = api.WorkspaceFactory.createTable('TableWorkspace')\n"
51 " ws.addColumn('str', 'name')\n"
52 " ws.addColumn('V3D', 'value')\n"
53 " ws.addColumn('str', 'type')\n"
54 " ws.addColumn('double', 'offset')\n"
55 " for (name, i) in zip('uvw', range(3)):\n"
58 " 'value': proj.getAxis(i),\n"
59 " 'type': proj.getType(i),\n"
60 " 'offset': proj.getOffset(i)\n"
63 " if OutputWorkspace is None:\n"
65 "kernel.funcinspect.process_frame(inspect.currentframe().f_back)\n"
67 " OutputWorkspace = lhs[1][0]\n"
69 " raise RuntimeError('createWorkspace failed to infer a name for its"
70 " output projection workspace. Please pass an"
71 " OutputWorkspace parameter to it.')\n"
72 " if OutputWorkspace:\n"
73 " AnalysisDataService[OutputWorkspace] = ws\n"
80 return global[
"createWorkspace"];
83void projSetAxis(
Projection &self,
size_t nd,
const object &data) {
91Projection_sptr projCtor3(
const object &d1,
const object &d2,
const object &d3) {
99 using namespace std::placeholders;
100 class_<Projection>(
"Projection", init<>(
"Default constructor creates a two dimensional projection"))
101 .def(init<const Mantid::Kernel::V3D &, const Mantid::Kernel::V3D &>(
102 "Constructs a 3 dimensional projection, with w as the cross product "
105 .def(init<const Mantid::Kernel::V3D &, const Mantid::Kernel::V3D &, const Mantid::Kernel::V3D &>(
106 "Constructs a 3 dimensional projection", args(
"u",
"v",
"w")))
107 .def(
"__init__", make_constructor(&projCtor2, default_call_policies(), (arg(
"u"), arg(
"v"))),
108 "Constructs a 3 dimensional projection, with w as the cross product "
110 .def(
"__init__", make_constructor(&projCtor3, default_call_policies(), (arg(
"u"), arg(
"v"), arg(
"w"))),
111 "Constructs a 3 dimensional projection")
112 .def(
"getOffset", &
Projection::getOffset, (arg(
"self"), arg(
"nd")),
"Returns the offset for the given dimension",
114 .def(
"getAxis", &
Projection::getAxis, (arg(
"self"), arg(
"nd")),
"Returns the axis for the given dimension",
116 .def(
"getType", &getUnit, (arg(
"self"), arg(
"dimension")),
"Returns the unit for the given dimension")
118 "Sets the offset for the given dimension", args(
"dimension",
"offset"))
120 "Sets the axis for the given dimension")
121 .def(
"setAxis", &projSetAxis, (arg(
"self"), arg(
"nd"), arg(
"data")),
"Sets the axis for the given dimension")
122 .def(
"setType", &setUnit, (arg(
"self"), arg(
"dimension"), arg(
"unit")),
"Sets the unit for the given dimension")
125 boost::mpl::vector2<Mantid::Kernel::V3D &, Projection &>()),
127 boost::mpl::vector3<void, Projection &, Mantid::Kernel::V3D>()))
130 boost::mpl::vector2<Mantid::Kernel::V3D &, Projection &>()),
132 boost::mpl::vector3<void, Projection &, Mantid::Kernel::V3D>()))
135 boost::mpl::vector2<Mantid::Kernel::V3D &, Projection &>()),
137 boost::mpl::vector3<void, Projection &, Mantid::Kernel::V3D>()))
140 boost::mpl::vector2<Mantid::Kernel::V3D &, Projection &>()),
141 make_function(std::bind(&projSetAxis, _1, 0, _2), default_call_policies(),
142 boost::mpl::vector3<void, Projection &, const object &>()))
145 boost::mpl::vector2<Mantid::Kernel::V3D &, Projection &>()),
146 make_function(std::bind(&projSetAxis, _1, 1, _2), default_call_policies(),
147 boost::mpl::vector3<void, Projection &, const object &>()))
150 boost::mpl::vector2<Mantid::Kernel::V3D &, Projection &>()),
151 make_function(std::bind(&projSetAxis, _1, 2, _2), default_call_policies(),
152 boost::mpl::vector3<void, Projection &, const object &>()))
153 .def(
"createWorkspace",
createWorkspace(),
"Create a TableWorkspace representing the projection");
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Kernel::V3D getAxis(size_t nd)
Retrieves the axis vector for the given dimension.
void setOffset(size_t nd, double offset)
Set the offset for a given dimension.
ProjectionUnit getUnit(size_t nd)
Retrives the unit of the given dimension.
void setUnit(size_t nd, ProjectionUnit unit)
Set the unit for a given dimension.
void setAxis(size_t nd, const Kernel::V3D &axis)
Set the axis vector for a given dimension.
double getOffset(size_t nd)
Retrieves the offset for the given dimension.
std::shared_ptr< T > createWorkspace(InitArgs... args)
std::shared_ptr< Projection > Projection_sptr
Takes a Python object and if it supports indexing and is of length 3 then it will attempt to convert ...