Qt:如何制作二维插值颜色的字段? [英] Qt: how do I make a field of 2d-interpolated colors?

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

问题描述

我是 C++ 的初学者,尤其是图形相关的.我想为我的图形视图制作一个动画背景,看起来像这样:

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 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 进行渲染.二维线性梯度称为双线性过滤

Then it is similar to #1 also you can instead of particle system do the rendering via QUADs/Squares. The 2D linear gradient is called Bilinear Filtering

    c00   -- x -->  c01

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

    c10              c11

哪里:

  • c00,c01,c10,c11 是角颜色
  • c(x,y) 是正方形内 x,y 位置上的颜色
  • 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线性插值:

        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:如何制作二维插值颜色的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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