From 72181a5b7b67d926450a01e3d6ff58a72e1570e3 Mon Sep 17 00:00:00 2001 From: Ethereal Date: Sun, 27 Feb 2011 13:31:15 -0700 Subject: [PATCH] Minor changes here and there. I think I will take some "time off", so to speak, and document the GViewport code a little. --- .aesalon.conf | 4 ++++ include/artisan/gviewport/BasicViewport.h | 9 +++---- include/artisan/gviewport/Point.h | 4 ++++ include/artisan/gviewport/Rect.h | 6 +++-- modules/cpuTime/src/artisan/Viewport.cpp | 4 ++-- src/artisan/gviewport/BasicViewport.cpp | 39 +++++++++++++++++-------------- src/artisan/gviewport/RenderedImage.cpp | 2 +- src/visualizer/Aesalon.cpp | 9 ++++++- 8 files changed, 48 insertions(+), 29 deletions(-) diff --git a/.aesalon.conf b/.aesalon.conf index d2f54ad..e58525c 100644 --- a/.aesalon.conf +++ b/.aesalon.conf @@ -12,3 +12,7 @@ module monitor { output="log:output%i.alog"; } +module visualizer { + # Use four threads in the global thread pool. + threadCount=4; +} diff --git a/include/artisan/gviewport/BasicViewport.h b/include/artisan/gviewport/BasicViewport.h index 2fe4395..a8f6195 100644 --- a/include/artisan/gviewport/BasicViewport.h +++ b/include/artisan/gviewport/BasicViewport.h @@ -36,13 +36,10 @@ public: Rect rangeLimit() const { return m_rangeLimit; } void limitRange(const Rect &newLimit) { m_rangeLimit = newLimit; } - - void translate(const Point &upperLeft); - void scale(double factor); - - void setViewport(const Rect &range); public slots: void acceptRenderedImage(RenderedImage *image); + void translate(const Point &upperLeft); + void setViewport(const Rect &range); void updateRange(const Rect &range); protected: virtual void resizeEvent(QResizeEvent *event); @@ -51,7 +48,7 @@ protected: virtual void mousePressEvent(QMouseEvent *event); virtual void wheelEvent(QWheelEvent *event); private: - void enqueue(Renderer *renderer); + void enqueue(const Rect &range); }; } // namespace GViewport diff --git a/include/artisan/gviewport/Point.h b/include/artisan/gviewport/Point.h index e199e9a..22cd139 100644 --- a/include/artisan/gviewport/Point.h +++ b/include/artisan/gviewport/Point.h @@ -28,6 +28,10 @@ public: double &y() { return m_y; } double y() const { return m_y; } + Point operator+(const Point &other) const { + return Point(m_x + other.m_x, m_y + other.m_y); + } + QPointF toQPoint() const { return QPointF(m_x, m_y); } diff --git a/include/artisan/gviewport/Rect.h b/include/artisan/gviewport/Rect.h index 8c3d57a..5db81a8 100644 --- a/include/artisan/gviewport/Rect.h +++ b/include/artisan/gviewport/Rect.h @@ -29,10 +29,12 @@ public: Rect() : m_left(0), m_right(0), m_top(0), m_bottom(0) {} Rect(double width, double height) : m_left(0), m_right(width), m_top(0), m_bottom(height) { normalize(); } Rect(QSizeF size) : m_left(0), m_right(size.width()), m_top(0), m_bottom(size.height()) { normalize(); } - Rect(double left, double right, double top, double bottom) : - m_left(left), m_right(right), m_top(top), m_bottom(bottom) { normalize(); } + Rect(double left, double right, double top, double bottom) + : m_left(left), m_right(right), m_top(top), m_bottom(bottom) { normalize(); } Rect(Point ul, Point lr) : m_left(ul.x()), m_right(lr.x()), m_top(ul.y()), m_bottom(lr.y()) { normalize(); } + Rect(Point ul, double width, double height) + : m_left(ul.x()), m_right(ul.x() + width), m_top(ul.y()), m_bottom(ul.y() + height) { normalize(); } double &left() { return m_left; } double left() const { return m_left; } diff --git a/modules/cpuTime/src/artisan/Viewport.cpp b/modules/cpuTime/src/artisan/Viewport.cpp index 6fdcb71..4bd7e3a 100644 --- a/modules/cpuTime/src/artisan/Viewport.cpp +++ b/modules/cpuTime/src/artisan/Viewport.cpp @@ -7,7 +7,7 @@ Viewport::Viewport(DataStore *dataStore) : Artisan::GViewport::BasicViewport(dataStore), m_dataStore(dataStore) { Message(Debug, "Creating cpuTime Viewport instance . . ."); - updateRange(Artisan::GViewport::Rect(1.0, 1.0)); + setViewport(Artisan::GViewport::Rect(1.0, 1.0)); Artisan::GViewport::Object *object = NULL; @@ -31,7 +31,7 @@ Viewport::Viewport(DataStore *dataStore) : Artisan::GViewport::BasicViewport(dat Artisan::GViewport::TreeType::Bound maxBound = data()->tree().bounds(); - updateRange(Artisan::GViewport::Rect(maxBound.range(0).start(), maxBound.range(0).end(), maxBound.range(1).start(), + setViewport(Artisan::GViewport::Rect(maxBound.range(0).start(), maxBound.range(0).end(), maxBound.range(1).start(), maxBound.range(1).end())); } diff --git a/src/artisan/gviewport/BasicViewport.cpp b/src/artisan/gviewport/BasicViewport.cpp index 379b8a4..7739ac6 100644 --- a/src/artisan/gviewport/BasicViewport.cpp +++ b/src/artisan/gviewport/BasicViewport.cpp @@ -27,39 +27,41 @@ BasicViewport::~BasicViewport() { } -void BasicViewport::translate(const Point &upperLeft) { - +void BasicViewport::acceptRenderedImage(RenderedImage *image) { + m_image.merge(*image); + delete image; + update(); } -void BasicViewport::scale(double factor) { +void BasicViewport::translate(const Point &upperLeft) { + RenderedImage image( + Rect(upperLeft, m_image.dataRange().width(), m_image.dataRange().height()), + m_image.pixelSize()); + image.merge(m_image); + update(); + enqueue(m_image.dataRange()); } void BasicViewport::setViewport(const Rect &range) { RenderedImage image(range, Rect(size())); image.merge(m_image); m_image = image; -} - -void BasicViewport::acceptRenderedImage(RenderedImage *image) { - m_image.merge(*image); - delete image; update(); + + enqueue(m_image.dataRange()); } void BasicViewport::updateRange(const Rect &range) { - RenderedImage image(range, Rect(size())); - image.merge(m_image); - m_image = image; - - enqueue(new Renderer(m_image.dataRange(), m_image.pixelSize(), m_data)); + enqueue(range); } void BasicViewport::resizeEvent(QResizeEvent *event) { RenderedImage image(m_image.dataRange(), Rect(event->size())); image.merge(m_image); m_image = image; - enqueue(new Renderer(m_image.dataRange(), Rect(event->size()), m_data)); + + enqueue(m_image.dataRange()); } void BasicViewport::paintEvent(QPaintEvent *event) { @@ -71,7 +73,7 @@ void BasicViewport::mouseMoveEvent(QMouseEvent *event) { Point diff = -(event->pos() - m_lastPoint); CoordinateMapper mapper(m_image); - updateRange(m_image.dataRange() + mapper.pixelToDataOffset(diff)); + translate(m_image.dataRange().topLeft() + mapper.pixelToDataOffset(diff)); m_lastPoint = event->pos(); } @@ -97,10 +99,13 @@ void BasicViewport::wheelEvent(QWheelEvent *event) { newRange.scaleWidth(factor); } - updateRange(newRange); + setViewport(newRange); } -void BasicViewport::enqueue(Renderer *renderer) { +void BasicViewport::enqueue(const Rect &rect) { + CoordinateMapper mapper(m_image); + Renderer *renderer = new Renderer(rect, mapper.dataToPixel(rect), m_data); + connect(renderer, SIGNAL(finishedRendering(RenderedImage *)), this, SLOT(acceptRenderedImage(RenderedImage *)), Qt::QueuedConnection); diff --git a/src/artisan/gviewport/RenderedImage.cpp b/src/artisan/gviewport/RenderedImage.cpp index a6b72db..98f3219 100644 --- a/src/artisan/gviewport/RenderedImage.cpp +++ b/src/artisan/gviewport/RenderedImage.cpp @@ -23,7 +23,7 @@ RenderedImage::RenderedImage(const Rect &dataRange, const Rect &pixelSize) m_image = QImage(m_pixelSize.width(), m_pixelSize.height(), QImage::Format_ARGB32); - m_image.fill(qRgb(255, 255, 255)); + m_image.fill(qRgb(qrand()%256, qrand()%256, qrand()%256)); m_painter = new QPainter(); } diff --git a/src/visualizer/Aesalon.cpp b/src/visualizer/Aesalon.cpp index 5c2b686..20d6e23 100644 --- a/src/visualizer/Aesalon.cpp +++ b/src/visualizer/Aesalon.cpp @@ -12,14 +12,21 @@ #include "visualizer/RootWindow.h" #include "util/MessageSystem.h" +#include "util/StringTo.h" #include "config/GlobalVault.h" int main(int argc, char *argv[]) { QApplication qapp(argc, argv); - Message(Debug, "Ideal thread count is " << QThread::idealThreadCount() << "."); + Message(Debug, "According to Qt, the ideal thread count is " << QThread::idealThreadCount() << "."); Config::GlobalVault gv; + int threadCount = Util::StringTo(gv.get("visualizer:threadCount")); + + if(threadCount != 0) { + Message(Debug, "Setting thread count to " << threadCount << "."); + QThreadPool::globalInstance()->setMaxThreadCount(threadCount); + } Visualizer::RootWindow rw; rw.show(); -- 2.11.4.GIT