C++ C+的彩色地图库+;它将给定值转换为红色、绿色和蓝色值

C++ C+的彩色地图库+;它将给定值转换为红色、绿色和蓝色值,c++,c,colors,visualization,C++,C,Colors,Visualization,我正在寻找一个colormap库,它可以将给定值转换为红色、绿色和蓝色值。类似于matlab的colormap功能[1]。优选的是C++。 [1] 我个人认为这对于一个库来说太简单了,我自己实现了它,他们的例子是C(你可以在维基百科上找到数学解释): /** *计算颜色渐变 *颜色:输出向量 *x:梯度(0和360之间) *最小值和最大值:RGB通道的变化(Move3D 0->1) */ void GroundColorMix(双*色、双x、双最小值、双最大值) { /* *红色=0 *绿色=1

我正在寻找一个colormap库,它可以将给定值转换为红色、绿色和蓝色值。类似于matlab的colormap功能[1]。优选的是C++。
[1] 我个人认为这对于一个库来说太简单了,我自己实现了它,他们的例子是C(你可以在维基百科上找到数学解释):

/**
*计算颜色渐变
*颜色:输出向量
*x:梯度(0和360之间)
*最小值和最大值:RGB通道的变化(Move3D 0->1)
*/
void GroundColorMix(双*色、双x、双最小值、双最大值)
{
/*
*红色=0
*绿色=1
*蓝色=2
*/
双posSlope=(最大最小)/60;
双负斜率=(最小-最大)/60;
如果(x<60)
{
颜色[0]=最大值;
颜色[1]=posSlope*x+min;
颜色[2]=min;
返回;
}
否则如果(x<120)
{
颜色[0]=负斜率*x+2*max+min;
颜色[1]=最大值;
颜色[2]=min;
返回;
}
否则如果(x<180)
{
颜色[0]=min;
颜色[1]=最大值;
颜色[2]=posSlope*x-2*max+min;
返回;
}
else if(x<240)
{
颜色[0]=min;
颜色[1]=负斜率*x+4*max+min;
颜色[2]=最大值;
返回;
}
否则如果(x<300)
{
颜色[0]=posSlope*x-4*max+min;
颜色[1]=min;
颜色[2]=最大值;
返回;
}
其他的
{
颜色[0]=最大值;
颜色[1]=min;
颜色[2]=负斜率*x+6*最大值;
返回;
}
}

是的,但您可能希望从不同的方案中进行选择,如在matlab中。在深夜被问到这一点时,当看到颜色选择器时,会想到这一点,这使问题变得非常简单:)
    /** 
     * Computes the color gradiant
     * color: the output vector 
     * x: the gradiant (beetween 0 and 360)
     * min and max: variation of the RGB channels (Move3D 0 -> 1)
     */
    void GroundColorMix(double* color, double x, double min, double max)
{
   /*
    * Red = 0
    * Green = 1
    * Blue = 2
    */
    double posSlope = (max-min)/60;
    double negSlope = (min-max)/60;

    if( x < 60 )
    {
        color[0] = max;
        color[1] = posSlope*x+min;
        color[2] = min;
        return;
    }
    else if ( x < 120 )
    {
        color[0] = negSlope*x+2*max+min;
        color[1] = max;
        color[2] = min;
        return;
    }
    else if ( x < 180  )
    {
        color[0] = min;
        color[1] = max;
        color[2] = posSlope*x-2*max+min;
        return;
    }
    else if ( x < 240  )
    {
        color[0] = min;
        color[1] = negSlope*x+4*max+min;
        color[2] = max;
        return;
    }
    else if ( x < 300  )
    {
        color[0] = posSlope*x-4*max+min;
        color[1] = min;
        color[2] = max;
        return;
    }
    else
    {
        color[0] = max;
        color[1] = min;
        color[2] = negSlope*x+6*max;
        return;
    }
}