Qt:如何做一个2d插值颜色的字段? [英] Qt: how do I make a field of 2d-interpolated colors?

查看:274
本文介绍了Qt:如何做一个2d插值颜色的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个初学者用c ++,尤其是图形相关。
我想为我的graphicsview做一个动画背景,看起来像这样:

I'm quite a beginner with c++, especially graphically related. I would like to make an animated background for my graphicsview which looks kind of like this:

渐变现场气流

图片代表湍流物体上的气流。
颜色必须基于一个值矩阵。

The picture represents the turbulence of an airflow over an object. The colors must be based on a matrix of values.

我只能找到如何用QT做单向渐变。

I can only find how to do single-direction gradients with QT.

如何设置?如何获得双向梯度?

How do I set this up? How do I get two-directional gradients?

/ * edit
从技术上讲,这不是一个渐变,而是一个颜色插值在2d节点上。
* /

/*edit It has been pointed out well that technically speaking this is not a gradient, but an color interpolation on a 2d array of nodes. */

推荐答案

你没有提供输入数据,所以没有人知道你真正想要实现什么!

Well you have not provided the input data so no one knows what you really want to achieve !


  1. 如果您有流动轨迹和质量

然后你可以使用一些粒子系统+重模糊/平滑滤波来实现这一点。对于沿着轨迹图的任何已知点,具有颜色的抖动圆取决于质量/温度/速度...和色标。它应该是中间固体和边缘透明。渲染后只是模糊/平滑的图像几次,这应该是它。使用的点越少,圆圈必须覆盖的区域很好,也可以做多遍,并随机改变点坐标以提高图像中的随机性...

Then you can use some particle system + heavy blurring/smoothing filtering to achieve this. For any known point along the trajectory plot a dithered circle with color depend on the mass/temp/velocity... and color scale. It should be solid in the middle and transparent on the edges. After rendering just blur/smooth the image few times and that should be it. The less points used the bigger the circles must be to cover the area nicely also can do it in multi pass and change the points coordinates randomly to improve randomness in the image...

如果你有场强/速度/温度或曾经的网格值

1 也可以代替粒子系统通过QUADs / Squares进行渲染。二维线性渐变称为双线性滤波

    c00   -- x -->  c01

      |
      |
      y      c(x,y)
      |
      |
      V

    c10              c11



b $ b

其中:

where:


  • c00,c01,c10,c11 $ x x c>正方形内的位置

  • x,y 在范围< 0,1> 为简单起见(但您可以使用适当的方程缩放)

  • c00,c01,c10,c11 are corner colors
  • c(x,y) is color on x,y position inside square
  • x,y are in range <0,1> for simplicity (but you can use any with appropriate equations scaling)

双线性插值 3x线性插值::

Bilinear interpolation is 3x linear interpolation:

        c0=c(x,0)=c00+((c01-c00)*x)
        c1=c(x,1)=c10+((c11-c10)*x)
        c(x,y)   =c0 +((c1 -c0 )*y)

这样用上面计算的颜色渲染正方形的所有像素,这就是你想要的。这种过滤通常在正方形或对角线之间的边缘产生伪影,以避免使用非线性过滤或模糊/平滑最终图像。

so render all pixels of the square with above computed colors and that is what you seek. This kind of filtering usually produce artifacts on the edges between squares or on diagonals to avoid that use non linear filtering or blur/smooth the final image

这篇关于Qt:如何做一个2d插值颜色的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆