12#include <boost/python/extract.hpp>
16#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
17#define NO_IMPORT_ARRAY
18#include <numpy/arrayobject.h>
20using boost::python::extract;
21using boost::python::len;
22using boost::python::object;
34PyObjectToVMD::PyObjectToVMD(
const object &p) : m_obj(p), m_alreadyVMD(false) {
36 extract<Kernel::VMD> converter(p);
37 if (converter.check()) {
43 const size_t length = len(p);
45 throw std::invalid_argument(
"Must be > 2 for conversion to VMD");
48 p.attr(
"__getitem__")(0);
49 }
catch (boost::python::error_already_set &) {
50 throw std::invalid_argument(std::string(
"Cannot convert object to VMD. "
51 "Expected a python sequence found: ") +
52 p.ptr()->ob_type->tp_name);
64 return extract<Kernel::VMD>(
m_obj)();
66 const size_t length = len(
m_obj);
68 for (
size_t i = 0; i < length; ++i) {
69 ret[i] = extract<float>(
m_obj[i])();
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Helper class which provides the Collimation Length for SANS instruments.
Kernel::VMD operator()()
Produces a VMD object from the given PyObject.
bool m_alreadyVMD
Is the object a wrapped instance of VMD.
const boost::python::object & m_obj
A reference to the object.