PyQt example: a few more refinements

metadata
Wenzel Jakob 2013-11-27 13:25:33 +01:00
parent 73b6dc4ce2
commit a2591285d7
4 changed files with 60 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -3278,6 +3278,56 @@ ref<Bitmap> 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;

View File

@ -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)