// Copyright (C) 2002-2003 Gideon May (gideon@computer.org) // // Permission to copy, use, sell and distribute this software is granted // provided this copyright notice appears in all copies. // Permission to modify the code and to distribute modified code is granted // provided this copyright notice appears in all copies, and a notice // that the code was modified is included with the copyright notice. // // This software is provided "as is" without express or implied warranty, // and with no claim as to its suitability for any purpose. #include #if (OSG_VERSION_MAJOR>=1) #include #include #include #include #include #include #include #include #include #include #include using namespace boost::python; namespace { osg::Vec4ub* vec4ubtuple(tuple data) { unsigned char x = 0, y = 0, z = 0, w = 1; // Fall through intentionally! switch (len(data)) { case 4: w = extract(data[3]); case 3: z = extract(data[2]); case 2: y = extract(data[1]); case 1: x = extract(data[0]); } return new osg::Vec4ub(x, y, z, w); } std::string osgVec4ub_repr(osg::Vec4ub * self) { std::ostringstream ost; ost << "Vec4ub(" << self->_v[0] << "," << self->_v[1] << "," << self->_v[2] << "," << self->_v[3] << ")"; return ost.str(); } std::string osgVec4ub_str(osg::Vec4ub * self) { std::ostringstream ost; ost << "(" << self->_v[0] << " " << self->_v[1] << " " << self->_v[2] << " " << self->_v[3] << ")"; return ost.str(); } #ifdef WIN32 inline void set_bytes(osg::Vec4ub * self, unsigned char x, unsigned char y, unsigned char z, unsigned char w) { self->set(x, y, z, w); } #endif inline void set(osg::Vec4ub * self, osg::Vec4ub& from) { * self = from; } inline void __setitem__(osg::Vec4ub * self, int idx, unsigned char val) { (*self)[idx] = val; } inline unsigned char __getitem__(osg::Vec4ub * self, int idx) { return (*self)[idx]; } inline unsigned char get_x(osg::Vec4ub * self) { return self->_v[0]; } inline void set_x(osg::Vec4ub * self, unsigned char x) { self->_v[0] = x; } inline unsigned char get_y(osg::Vec4ub * self) { return self->_v[1]; } inline void set_y(osg::Vec4ub * self, unsigned char y) { self->_v[1] = y; } inline unsigned char get_z(osg::Vec4ub * self) { return self->_v[2]; } inline void set_z(osg::Vec4ub * self, unsigned char z) { self->_v[2] = z; } inline unsigned char get_w(osg::Vec4ub * self) { return self->_v[3]; } inline void set_w(osg::Vec4ub * self, unsigned char z) { self->_v[3] = z; } } // namespace namespace PyOSG { void init_Vec4ub() { // Complete class_("Vec4ub") .def(init()) .def(init()) .def("__init__", make_constructor(vec4ubtuple)) .def(self == self) .def(self != self) .def(self < self) #ifdef WIN32 .def("set", set_bytes) .def("__getitem__", &__getitem__) .def("x", &get_x) .def("y", &get_y) .def("z", &get_z) .def("w", &get_w) #else .def("set", &osg::Vec4ub::set) .def("__getitem__", (unsigned char &(osg::Vec4ub::*)(unsigned int)) &osg::Vec4ub::operator[], return_value_policy()) .def("r", (unsigned char (osg::Vec4ub::*)() const) &osg::Vec4ub::r) .def("g", (unsigned char (osg::Vec4ub::*)() const) &osg::Vec4ub::g) .def("b", (unsigned char (osg::Vec4ub::*)() const) &osg::Vec4ub::b) .def("a", (unsigned char (osg::Vec4ub::*)() const) &osg::Vec4ub::a) #endif .def("__setitem__", &__setitem__) .add_property("_x", get_x, set_x) .add_property("_y", get_y, set_y) .add_property("_z", get_z, set_z) .add_property("_w", get_w, set_w) .def(self * float()) .def(self *= float()) .def(self / float()) .def(self /= float()) .def(self + self) .def(self += self) .def(self - self) .def(self -= self) .def("__str__", &osgVec4ub_str) .def("__repr__", &osgVec4ub_repr) ; } } #endif // (OSG_VERSION_MAJOR>=1)