python layer improvements

metadata
Wenzel Jakob 2011-08-17 05:10:16 -04:00
parent cedab7e413
commit e7225da4ca
6 changed files with 26 additions and 6 deletions

View File

@ -154,11 +154,18 @@ public:
std::string getString(const std::string &name, const std::string &defVal) const;
/// Store an array containing the names of all stored properties
inline void putPropertyNames(std::vector<std::string> &results) const {
inline void putNames(std::vector<std::string> &results) const {
for (std::map<std::string, Element>::const_iterator it = m_elements.begin();
it != m_elements.end(); ++it)
results.push_back((*it).first);
}
/// Return an array containing the names of all stored properties
inline std::vector<std::string> getNames() const {
std::vector<std::string> results;
putNames(results);
return results;
}
/// Manually mark a certain property as queried
void markQueried(const std::string &name) const;

View File

@ -110,7 +110,7 @@ std::string Properties::toString() const {
oss << "Properties[" << endl
<< " pluginName = \"" << m_pluginName << "\"," << endl
<< " elements = {" << endl;
for (; it != m_elements.end(); ++it) {
while (it != m_elements.end()) {
oss << " \"" << (*it).first << "\" -> ";
const ElementData &data = (*it).second.data;
EPropertyType type = boost::apply_visitor(type_visitor(), data);
@ -143,7 +143,9 @@ std::string Properties::toString() const {
default:
SLog(EError, "Encountered an unknown property type!");
}
oss << "," << endl;
if (++it != m_elements.end())
oss << ",";
oss << endl;
}
oss << " }" << endl
<< "]" << endl;

View File

@ -251,11 +251,13 @@ void export_core() {
bp::return_value_policy<bp::copy_const_reference>())
.def("setID", &Properties::setPluginName)
.def("getType", &Properties::getType)
.def("getNames", &Properties::getNames)
.def("hasProperty", &Properties::hasProperty)
.def("wasQueried", &Properties::wasQueried)
.def("markQueried", &Properties::markQueried)
.def("__getitem__", &properties_wrapper::get)
.def("__setitem__", &properties_wrapper::set)
.def("__contains__", &Properties::hasProperty)
.def("__str__", &Properties::toString);
bp::scope scope4 = coreModule;
@ -530,7 +532,6 @@ void export_core() {
.def("trace", &Matrix4x4::trace)
.def("det", &Matrix4x4::det)
.def("serialize", &Matrix4x4::serialize)
.def("transpose", &Matrix4x4::transpose)
.def(bp::self != bp::self)
.def(bp::self == bp::self)
.def(-bp::self)
@ -555,6 +556,12 @@ BOOST_PYTHON_MODULE(mitsuba) {
bp::object package = bp::scope();
package.attr("__path__") = "mitsuba";
/* Basic STL containers */
bp::class_<StringVector>("StringVector")
.def(bp::vector_indexing_suite<StringVector>());
bp::class_<StringMap>("StringMap")
.def(bp::map_indexing_suite<StringMap>());
/* Automatically take care of the framework
initialization / shutdown */
initializeFramework();

View File

@ -33,6 +33,8 @@ namespace boost {
}
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
namespace bp = boost::python;
@ -49,6 +51,8 @@ template <typename T> void registerClass() {
boost::python::register_ptr_to_python< mitsuba::ref<T> >();
}
typedef std::vector<std::string> StringVector;
typedef std::map<std::string, std::string> StringMap;
#endif /* __MTSPY_H */

View File

@ -69,7 +69,7 @@ static void setProperties(QDomDocument &doc, QDomElement &element,
element.setAttribute("type", props.getPluginName().c_str());
std::vector<std::string> propertyNames;
props.putPropertyNames(propertyNames);
props.putNames(propertyNames);
for (std::vector<std::string>::const_iterator it = propertyNames.begin();
it != propertyNames.end(); ++it) {
QDomElement property;

View File

@ -132,7 +132,7 @@ void TreeItem::setProperty(const std::string &name, const Properties &props) {
void TreeItem::setProperties(const Properties &props) {
std::vector<std::string> propertyNames;
props.putPropertyNames(propertyNames);
props.putNames(propertyNames);
for (std::vector<std::string>::const_iterator it = propertyNames.begin();
it != propertyNames.end(); ++it)