/*
This file is part of Mitsuba, a physically based rendering system.
Copyright (c) 2007-2011 by Wenzel Jakob and others.
Mitsuba is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License Version 3
as published by the Free Software Foundation.
Mitsuba 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 .
*/
#if !defined(__MTSPY_H)
#define __MTSPY_H
#include
#define BP_STRUCT(Name, Init) \
bp::class_ Name ##_struct(#Name, Init); \
bp::register_ptr_to_python(); \
Name ##_struct
#define BP_CLASS(Name, Base, Init) \
bp::class_, bp::bases, boost::noncopyable> Name ##_class(#Name, Init); \
bp::register_ptr_to_python(); \
Name ##_class
#define BP_WRAPPED_CLASS(Name, Wrapper, Base, Init) \
bp::class_, bp::bases, boost::noncopyable> Name ##_class(#Name, Init); \
bp::register_ptr_to_python(); \
Name ##_class
#define BP_IMPLEMENT_VECTOR_OPS(Name, Scalar, Size) \
Name ##_struct \
.def(bp::init()) \
.def(bp::self != bp::self) \
.def(bp::self == bp::self) \
.def(-bp::self) \
.def(bp::self + bp::self) \
.def(bp::self += bp::self) \
.def(bp::self - bp::self) \
.def(bp::self -= bp::self) \
.def(bp::self *= Scalar()) \
.def(bp::self * Scalar()) \
.def(Scalar() * bp::self) \
.def(bp::self / Scalar()) \
.def(bp::self /= Scalar()) \
.def("serialize", &Name::serialize) \
.def("__str__", &Name::toString) \
.def("__len__", &FixedSizeSupport::len) \
.def("__getitem__", &FixedSizeSupport::get) \
.def("__setitem__", &FixedSizeSupport::set)
#define BP_IMPLEMENT_POINT_OPS(Name, Scalar, Size) \
Name ##_struct \
.def(bp::init()) \
.def(bp::self != bp::self) \
.def(bp::self == bp::self) \
.def(Scalar() * bp::self) \
.def(-bp::self) \
.def(bp::self + Name::vector_type()) \
.def(bp::self += Name::vector_type()) \
.def(bp::self - Name::vector_type()) \
.def(bp::self -= Name::vector_type()) \
.def(bp::self - bp::self) \
.def(bp::self *= Scalar()) \
.def(bp::self * Scalar()) \
.def(bp::self / Scalar()) \
.def(bp::self /= Scalar()) \
.def("serialize", &Name::serialize) \
.def("__str__", &Name::toString) \
.def("__len__", &FixedSizeSupport::len) \
.def("__getitem__", &FixedSizeSupport::get) \
.def("__setitem__", &FixedSizeSupport::set)
#define BP_SETSCOPE(value) do { \
bp::detail::current_scope = value.ptr(); \
} while (0);
#define BP_RETURN_CONSTREF bp::return_value_policy()
#define BP_RETURN_NONCONSTREF bp::return_value_policy()
#define BP_RETURN_VALUE bp::return_value_policy()
#define BP_RETURN_INTREF bp::return_internal_reference<>()
namespace boost {
namespace python {
template T* get_pointer(mitsuba::ref & p) {
return p.get();
}
template const T* get_pointer(const mitsuba::ref & p) {
return p.get();
}
}
}
#include
#include
#include
namespace bp = boost::python;
/* Support ref<..> smart pointers */
namespace boost {
namespace python {
template struct pointee< mitsuba::ref > {
typedef T type;
};
}
}
template class FixedSizeSupport {
public:
static Scalar get(const T &value, int i) {
using namespace mitsuba;
if (i < 0 || i >= Size) {
SLog(EError, "Index %i is out of range!", i);
return 0.0f;
}
return value[i];
}
static void set(T &value, int i, Scalar arg) {
using namespace mitsuba;
if (i < 0 || i >= Size)
SLog(EError, "Index %i is out of range!", i);
else
value[i] = arg;
}
static int len(const T &) {
return Size;
}
};
typedef std::vector StringVector;
typedef std::map StringMap;
#endif /* __MTSPY_H */