void register_iterator_pair(const std::string& name) { using namespace boost::python; using self_ns::str; class_<std::pair<It,It> >(name.c_str(), no_init) .def("__iter__", range(&iterator_pair<It>::begin, &iterator_pair<It>::end)) .def(str(self)); }
// Declare the OIIO ROI class to Python void declare_roi() { class_<ROI>("ROI") .def_readwrite("xbegin", &ROI::xbegin) .def_readwrite("xend", &ROI::xend) .def_readwrite("ybegin", &ROI::ybegin) .def_readwrite("yend", &ROI::yend) .def_readwrite("zbegin", &ROI::zbegin) .def_readwrite("zend", &ROI::zend) .def_readwrite("chbegin", &ROI::chbegin) .def_readwrite("chend", &ROI::chend) .def(init<int,int,int,int>()) .def(init<int,int,int,int,int,int>()) .def(init<int,int,int,int,int,int,int,int>()) .def(init<const ROI&>()) .add_property("defined", &ROI::defined) .add_property("width", &ROI::width) .add_property("height", &ROI::height) .add_property("depth", &ROI::depth) .add_property("nchannels", &ROI::nchannels) .add_property("npixels", &ROI::npixels) .def_readonly("All", &ROI_All) // Define Python str(ROI), it automatically uses '<<' .def(str(self)) // __str__ // roi_union, roi_intersection, get_roi(spec), get_roi_full(spec) // set_roi(spec,newroi), set_roi_full(newroi) // overloaded operators .def(self == other<ROI>()) // operator== .def(self != other<ROI>()) // operator!= ; def("union", &roi_union); def("intersection", &roi_intersection); def("get_roi", &get_roi); def("get_roi_full", &get_roi_full); def("set_roi", &set_roi); def("set_roi_full", &set_roi_full); }
// Declare the OIIO TypeDesc type to Python void declare_typedesc() { enum_<TypeDesc::BASETYPE>("BASETYPE") .value("UNKNOWN", TypeDesc::UNKNOWN) .value("NONE", TypeDesc::NONE) .value("UCHAR", TypeDesc::UCHAR) .value("UINT8", TypeDesc::UINT8) .value("CHAR", TypeDesc::CHAR) .value("INT8", TypeDesc::INT8) .value("USHORT", TypeDesc::USHORT) .value("UINT16", TypeDesc::UINT16) .value("SHORT", TypeDesc::SHORT) .value("INT16", TypeDesc::INT16) .value("UINT", TypeDesc::UINT) .value("UINT32", TypeDesc::UINT32) .value("INT", TypeDesc::INT) .value("INT32", TypeDesc::INT32) .value("ULONGLONG", TypeDesc::ULONGLONG) .value("UINT64", TypeDesc::UINT64) .value("LONGLONG", TypeDesc::LONGLONG) .value("INT64", TypeDesc::INT64) .value("HALF", TypeDesc::HALF) .value("FLOAT", TypeDesc::FLOAT) .value("DOUBLE", TypeDesc::DOUBLE) .value("STRING", TypeDesc::STRING) .value("PTR", TypeDesc::PTR) .value("LASTBASE", TypeDesc::LASTBASE) .export_values() ; enum_<TypeDesc::AGGREGATE>("AGGREGATE") .value("SCALAR", TypeDesc::SCALAR) .value("VEC2", TypeDesc::VEC2) .value("VEC3", TypeDesc::VEC3) .value("VEC4", TypeDesc::VEC4) .value("MATRIX44", TypeDesc::MATRIX44) .export_values() ; enum_<TypeDesc::VECSEMANTICS>("VECSEMANTICS") .value("NOXFORM", TypeDesc::NOXFORM) .value("NOSEMANTICS", TypeDesc::NOSEMANTICS) .value("COLOR", TypeDesc::COLOR) .value("POINT", TypeDesc::POINT) .value("VECTOR", TypeDesc::VECTOR) .value("NORMAL", TypeDesc::NORMAL) .value("TIMECODE", TypeDesc::TIMECODE) .value("KEYCODE", TypeDesc::KEYCODE) .export_values() ; class_<TypeDesc>("TypeDesc") // basetype, aggregate, and vecsemantics should look like BASETYPE, // AGGREGATE, VECSEMANTICS, but since they are stored as unsigned // char, def_readwrite() doesn't do the right thing. Instead, we // use set_foo/get_foo wrappers, but from Python it looks like // regular member access. .add_property("basetype", &TypeDesc_get_basetype, &TypeDesc_set_basetype) .add_property("aggregate", &TypeDesc_get_aggregate, &TypeDesc_set_aggregate) .add_property("vecsemantics", &TypeDesc_get_vecsemantics, &TypeDesc_set_vecsemantics) .def_readwrite("arraylen", &TypeDesc::arraylen) // Constructors: () [defined implicitly], (base), (base, agg), // (base,agg,vecsem), (base,agg,vecsem,arraylen), string. .def(init<TypeDesc::BASETYPE>()) .def(init<TypeDesc::BASETYPE, TypeDesc::AGGREGATE>()) .def(init<TypeDesc::BASETYPE, TypeDesc::AGGREGATE, TypeDesc::VECSEMANTICS>()) .def(init<TypeDesc::BASETYPE, TypeDesc::AGGREGATE, TypeDesc::VECSEMANTICS, int>()) .def(init<const char *>()) // Unfortunately, overloading the int varieties, as we do in C++, // doesn't seem to work properly, it can't distinguish between an // int and an AGGREGATE, for example. Maybe in C++11 with strong // enum typing, it will work. But for now, we must forego these // variants of the constructors: // .def(init<TypeDesc::BASETYPE, int>()) // .def(init<TypeDesc::BASETYPE, TypeDesc::AGGREGATE, int>()) .def("c_str", &TypeDesc::c_str) .def("numelements", &TypeDesc::numelements) .def("size", &TypeDesc::size) .def("elementtype", &TypeDesc::elementtype) .def("elementsize", &TypeDesc::elementsize) .def("basesize", &TypeDesc::basesize) .def("fromstring", &TypeDesc_fromstring) .def("equivalent", &TypeDesc::equivalent) .def("unarray", &TypeDesc::unarray) .def("is_vec3", &TypeDesc::is_vec3) .def("is_vec4", &TypeDesc::is_vec4) // overloaded operators .def(self == other<TypeDesc>()) // operator== .def(self != other<TypeDesc>()) // operator!= // Define Python str(TypeDesc), it automatically uses '<<' .def(str(self)) // __str__ // Static members of pre-constructed types .def_readonly("TypeFloat", &TypeDesc::TypeFloat) .def_readonly("TypeColor", &TypeDesc::TypeColor) .def_readonly("TypeString", &TypeDesc::TypeString) .def_readonly("TypeInt", &TypeDesc::TypeInt) .def_readonly("TypeHalf", &TypeDesc::TypeHalf) .def_readonly("TypePoint", &TypeDesc::TypePoint) .def_readonly("TypeVector", &TypeDesc::TypeVector) .def_readonly("TypeNormal", &TypeDesc::TypeNormal) .def_readonly("TypeMatrix", &TypeDesc::TypeMatrix) .def_readonly("TypeTimeCode", &TypeDesc::TypeTimeCode) .def_readonly("TypeKeyCode", &TypeDesc::TypeKeyCode) .def_readonly("TypeFloat4", &TypeDesc::TypeFloat4) ; }