简体   繁体   English

在C ++ Qt中将2D向量/ 2D数组显示为简单图形

[英]Display 2d vector/2d array into simple figure in c++ Qt

I have to compare two 2d vectors ( vect_2d_a and vect_2d_b ) and as a result I will construct a 2d vector/2d array ( vect_compare_result ) comprising the difference in value of vect_2d_a and vect_2d_b . 我必须比较两个2d向量( vect_2d_avect_2d_b ),结果将构造一个2d向量/ 2d数组( vect_compare_result ),其中包含vect_2d_avect_2d_b值之vect_2d_b

Basically I can simply print the vect_compare_result and view it, but I would like to see it as a figure with simple boxes indicating the difference value in pixels (like colorbar in matlab). 基本上,我可以简单地打印vect_compare_result并查看它,但是我希望将其看作一个带有简单框的图,该框以像素为单位指示差异值(例如matlab中的vect_compare_result )。

Is it possible to display a simple 2d vector into a figure using Qimg or something? 是否可以使用Qimg或其他将简单的2d向量显示在图形中?

Priya 普里亚

Assuming that size of your vector is nxn : 假设向量的大小为nxn

QImage image(n, n, QImage::Format_RGB32);
QRgb value;

for (int i=0;i<N;++i) {
    for (int j=0;j<N;++j) {
        value = getColor(vect_compare_result); //a function that returns color based on value
        image.setPixel(i, j, value);
    }
}

If you want your pixels to be bigger (like one box is 5x5 real pixels): 如果您希望像素更大(例如一个盒子是5x5真实像素):

int box_size = 5;
QImage image(n * box_size, n * box_size, QImage::Format_RGB32);
QRgb value;

for (int i=0;i<N;++i) {
    for (int j=0;j<N;++j) {
        value = getColor(vect_compare_result);
        for (int k=0;k<box_size;++k)
            for (int l=0;l<box_size;++l)
                image.setPixel(i+k, j+l, value);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM