| 817 | }; |
| 818 | |
| 819 | void MatrixView::updateImage() { |
| 820 | #ifndef SDK |
| 821 | WAIT_CURSOR; |
| 822 | m_image = QImage(m_matrix->columnCount(), m_matrix->rowCount(), QImage::Format_ARGB32); |
| 823 | |
| 824 | // find min/max value |
| 825 | double dmax = -DBL_MAX, dmin = DBL_MAX; |
| 826 | const auto* data = static_cast<QVector<QVector<double>>*>(m_matrix->data()); |
| 827 | const int width = m_matrix->columnCount(); |
| 828 | const int height = m_matrix->rowCount(); |
| 829 | for (int col = 0; col < width; ++col) { |
| 830 | for (int row = 0; row < height; ++row) { |
| 831 | const double value = (data->operator[](col))[row]; |
| 832 | if (dmax < value) |
| 833 | dmax = value; |
| 834 | if (dmin > value) |
| 835 | dmin = value; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | // update the image |
| 840 | auto* manager = ColorMapsManager::instance(); |
| 841 | QPixmap pix; |
| 842 | manager->render(pix, QLatin1String("viridis100")); // dummy render to get the color vector initialized |
| 843 | const auto& colors = manager->colors(); |
| 844 | auto* pool = QThreadPool::globalInstance(); |
| 845 | int range = ceil(double(m_image.height()) / pool->maxThreadCount()); |
| 846 | for (int i = 0; i < pool->maxThreadCount(); ++i) { |
| 847 | const int start = i * range; |
| 848 | int end = (i + 1) * range; |
| 849 | if (end > m_image.height()) |
| 850 | end = m_image.height(); |
| 851 | auto* task = new UpdateImageTask(start, end, m_image, data, dmin, dmax, colors); |
| 852 | pool->start(task); |
| 853 | } |
| 854 | pool->waitForDone(); |
| 855 | |
| 856 | if (m_zoomFactor == 1.) { |
| 857 | m_imageLabel->resize(width, height); |
| 858 | m_imageLabel->setPixmap(QPixmap::fromImage(m_image)); |
| 859 | } else { |
| 860 | const int w = static_cast<int>(std::rint(m_image.width() * m_zoomFactor)); |
| 861 | const int h = static_cast<int>(std::rint(m_image.height() * m_zoomFactor)); |
| 862 | m_imageLabel->resize(w, h); |
| 863 | QImage zoomedImage = m_image.scaled(w, h); |
| 864 | m_imageLabel->setPixmap(QPixmap::fromImage(zoomedImage)); |
| 865 | } |
| 866 | m_imageIsDirty = false; |
| 867 | RESET_CURSOR; |
| 868 | #endif |
| 869 | } |
| 870 | |
| 871 | // ############################# matrix related slots ########################### |
| 872 | void MatrixView::switchView(QAction* action) { |