diff --git a/doc/python.tex b/doc/python.tex index 2f0e4c56..bf230da4 100644 --- a/doc/python.tex +++ b/doc/python.tex @@ -479,7 +479,7 @@ from PyQt4.QtGui import QApplication, QMainWindow, QPainter, QImage class MitsubaView(QMainWindow): def __init__(self): super(MitsubaView, self).__init__() - self.setWindowTitle('Mitsuba/Qt demo') + self.setWindowTitle('Mitsuba/PyQt demo') self.initializeMitsuba() self.image = self.render(self.createScene()) self.resize(self.image.width(), self.image.height()) @@ -598,7 +598,7 @@ class MitsubaRenderBuffer(RenderListener): """ Callback: a worker thread started rendering an image block. Draw a rectangle to highlight this """ _ = self._get_film_ensure_initialized(job) - self.bitmap.drawRect(wu.getOffset(), wu.getSize(), Spectrum(0.8)) + self.bitmap.drawWorkUnit(wu.getOffset(), wu.getSize(), thr) self._potentially_send_update() def workEndEvent(self, job, wr): @@ -710,7 +710,7 @@ class MitsubaDemo(QMainWindow): status.setContentsMargins(0,0,5,0) status.addPermanentWidget(progress) status.setSizeGripEnabled(False) - self.setWindowTitle('Mitsuba/Qt demo') + self.setWindowTitle('Mitsuba/PyQt demo') self.setCentralWidget(self.rwidget) # Hide the scroll bar once the rendering is done diff --git a/include/mitsuba/core/bitmap.h b/include/mitsuba/core/bitmap.h index 6d8ce6c3..a0380fe1 100644 --- a/include/mitsuba/core/bitmap.h +++ b/include/mitsuba/core/bitmap.h @@ -446,6 +446,12 @@ public: /// Draw a filled rectangle with the specified position and size void fillRect(Point2i offset, Vector2i size, const Spectrum &value); + /** + * \brief Convenience function to visually indicate that a thread is + * working on a certain part of an image + */ + void drawWorkUnit(const Point2i &offset, const Vector2i &size, int worker); + /// Bitmap equality operator (useful for unit-tests etc.) bool operator==(const Bitmap &bitmap) const; diff --git a/src/libcore/bitmap.cpp b/src/libcore/bitmap.cpp index b95f936c..bb88d531 100644 --- a/src/libcore/bitmap.cpp +++ b/src/libcore/bitmap.cpp @@ -3278,6 +3278,56 @@ ref Bitmap::expand() { return output; } +void Bitmap::drawWorkUnit(const Point2i &offset, const Vector2i &size, int worker) { + int ox = offset.x, oy = offset.y, + ex = ox + size.x, ey = oy + size.y; + if (size.x < 3 || size.y < 3) + return; + + const float *color = NULL; + + /* Use desaturated colors to highlight the worker + responsible for rendering the current image */ + const float white[] = { 1.0f, 1.0f, 1.0f }; + const float red[] = { 1.0f, 0.3f, 0.3f }; + const float green[] = { 0.3f, 1.0f, 0.3f }; + const float blue[] = { 0.3f, 0.3f, 1.0f }; + const float gray[] = { 0.5f, 0.5f, 0.5f }; + const float yellow[] = { 1.0f, 1.0f, 0.0f }; + const float magenta[] = { 1.0f, 0.3f, 1.0f }; + const float turquoise[] = { 0.3f, 1.0f, 1.0f }; + + switch (worker % 8) { + case 1: color = green; break; + case 2: color = yellow; break; + case 3: color = blue; break; + case 4: color = gray; break; + case 5: color = red; break; + case 6: color = magenta; break; + case 7: color = turquoise; break; + case 0: + default: + color = white; + break; + } + + float scale = .7f * (color[0] * 0.212671f + color[1] * 0.715160f + color[2] * 0.072169f); + + Spectrum spec; + spec.fromLinearRGB(color[0]*scale, + color[1]*scale, + color[2]*scale); + + drawHLine(oy, ox, ox + 3, spec); + drawHLine(oy, ex - 4, ex - 1, spec); + drawHLine(ey - 1, ox, ox + 3, spec); + drawHLine(ey - 1, ex - 4, ex - 1, spec); + drawVLine(ox, oy, oy + 3, spec); + drawVLine(ex - 1, oy, oy + 3, spec); + drawVLine(ex - 1, ey - 4, ey - 1, spec); + drawVLine(ox, ey - 4, ey - 1, spec); +} + std::ostream &operator<<(std::ostream &os, const Bitmap::EPixelFormat &value) { switch (value) { case Bitmap::ELuminance: os << "luminance"; break; diff --git a/src/libpython/core.cpp b/src/libpython/core.cpp index 01e18ddc..dad3a90d 100644 --- a/src/libpython/core.cpp +++ b/src/libpython/core.cpp @@ -1249,6 +1249,7 @@ void export_core() { .def("getMetadata", get_metadata, BP_RETURN_VALUE) .def("drawRect", &Bitmap::drawRect) .def("fillRect", &Bitmap::fillRect) + .def("drawWorkUnit", &Bitmap::drawWorkUnit) .def("convert", &bitmap_convert_1, BP_RETURN_VALUE) .def("convert", &bitmap_convert_2, BP_RETURN_VALUE) .def("convert", &bitmap_convert_3, BP_RETURN_VALUE)