POV-Ray : Newsgroups : povray.general : colors map interpolation Server Time
27 Dec 2024 03:54:23 EST (-0500)
  colors map interpolation (Message 1 to 6 of 6)  
From: kurtz le pirate
Subject: colors map interpolation
Date: 20 Nov 2022 11:28:21
Message: <637a55a5$1@news.povray.org>
Hello,

Let's assume that we have a colors map :
#declare MyColorMap = color_map {
  [ 0.00 rgb < 1.00, 0.00, 0.00> ]
  [ 0.50 rgb < 1.00, 1.00, 0.00> ]
  [ 1.00 rgb < 0.00, 0.00, 1.00> ]
  }

Is there a way to recover the color for specific index ?
Something that looks like : GetColor(MyColorMap, index)





-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Bald Eagle
Subject: Re: colors map interpolation
Date: 20 Nov 2022 12:50:00
Message: <web.637a680ff841873a1f9dae3025979125@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:
> Hello,
>
> Let's assume that we have a colors map :
> #declare MyColorMap = color_map {
>   [ 0.00 rgb < 1.00, 0.00, 0.00> ]
>   [ 0.50 rgb < 1.00, 1.00, 0.00> ]
>   [ 1.00 rgb < 0.00, 0.00, 1.00> ]
>   }
>
> Is there a way to recover the color for specific index ?
> Something that looks like : GetColor(MyColorMap, index)

Sure - I think you could take something like a gradient pigment pattern, apply
that color mapping to it, and then use that as a function.   Then you could pass
in a space coordinate with a vector component parallel to that gradient, and the
function would return the interpolated color vector as a result.
You would of course, have to write / generate 3 functions - one for the .r, .g,
and .b components.

https://wiki.povray.org/content/Reference:Color_Map

Alternatively, you could roll your own and use a spline function to do the
interpolation, in case there something special that the above can't handle.


Post a reply to this message

From: Bald Eagle
Subject: Re: colors map interpolation
Date: 20 Nov 2022 15:10:00
Message: <web.637a8917f841873a1f9dae3025979125@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> Sure - I think you could take something like a gradient pigment pattern, apply
> that color mapping to it, and then use that as a function.   Then you could pass
> in a space coordinate with a vector component parallel to that gradient, and the
> function would return the interpolated color vector as a result.
> You would of course, have to write / generate 3 functions - one for the .r, .g,
> and .b components.



Like this:



#version 3.8;
global_settings {
 assumed_gamma 1.0
}


#include "math.inc"

#declare E = 0.000001;

#declare Camera_Orthographic = true;  //
<----################################################################################

#declare Camera_Position = <0, 0, -20>;  // front view
#declare Camera_Look_At  = <0, 0,  0> ;
#declare Fraction = 1;     // functions as a zoom for the orthographic view: 4
zooms in 4x, 8 zooms in 8x, etc.

#declare Aspect = image_width/image_height;
// ###########################################
camera {
 #if (Camera_Orthographic = true)
  orthographic
  right     x*image_width/(Fraction)
  up   y*image_height/(Fraction)
 #else
  right     x*image_width/image_height
  up y
 #end
 location  Camera_Position
 look_at   Camera_Look_At}
// ###########################################

sky_sphere {pigment {rgb 1}}
light_source {<0, 0, -image_width> color rgb 1}



#declare MyColorMap = color_map {
  [ 0.00 rgb < 1.00, 0.00, 0.00> ]
  [ 0.50 rgb < 1.00, 1.00, 0.00> ]
  [ 1.00 rgb < 0.00, 0.00, 1.00> ]
  }


#declare Gradient = pigment {gradient x color_map {MyColorMap}}

box {<0, image_height/3, 0>, < image_width, 2*image_height/3, 0.01> pigment
{Gradient scale image_width} translate -x*image_width/2}


#declare GradientFunction = function {pigment {Gradient}}




#for (XX, 16, 640-16, 16)
 #local R = GradientFunction (XX/image_width, 0, 0).red;
 #local G = GradientFunction (XX/image_width, 0, 0).green;
 #local B = GradientFunction (XX/image_width, 0, 0).blue;
 sphere {<XX, 0, 0> 5 pigment {rgb <R, G, B>} translate -x*image_width/2}
#end


Post a reply to this message


Attachments:
Download 'colormapinterpolation.png' (18 KB)

Preview of image 'colormapinterpolation.png'
colormapinterpolation.png


 

From: kurtz le pirate
Subject: Re: colors map interpolation
Date: 21 Nov 2022 11:29:57
Message: <637ba785$1@news.povray.org>
On 20/11/2022 21:07, Bald Eagle wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> 
>> Sure - I think you could take something like a gradient pigment pattern, apply
>> that color mapping to it, and then use that as a function.   Then you could pass
>> in a space coordinate with a vector component parallel to that gradient, and the
>> function would return the interpolated color vector as a result.
>> You would of course, have to write / generate 3 functions - one for the .r, .g,
>> and .b components.
> 
> 
> 
> Like this:
> ...


Waouh, impressive !!!

Based on your brilliant example, here is the macro :
// -------------------------------------------------------------------
#macro GetColor(thisColorMap, thisEntry)
 #local index = max(0.0, min(thisEntry, 1.0));

 #local Gradient = pigment { gradient x color_map { thisColorMap } }
 #local GradientFunction = function { pigment { Gradient } }

 #local R = GradientFunction (index, 0, 0).red;
 #local G = GradientFunction (index, 0, 0).green;
 #local B = GradientFunction (index, 0, 0).blue;

 rgb <R, G, B>
#end
// -------------------------------------------------------------------


And used like that :
sphere {
  <XX, 0, 0> 5
 pigment { GetColor(MyColorMap, XX/image_width)  }
 translate -x*image_width/2
 }



-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: colors map interpolation
Date: 22 Nov 2022 07:15:00
Message: <web.637cbc5ef841873aaaf434a689db30a9@news.povray.org>
kurtz le pirate <kur### [at] gmailcom> wrote:
> On 20/11/2022 21:07, Bald Eagle wrote:
> > "Bald Eagle" <cre### [at] netscapenet> wrote:
> >
> >> Sure - I think you could take something like a gradient pigment pattern, apply
> >> that color mapping to it, and then use that as a function.   Then you could pass
> >> in a space coordinate with a vector component parallel to that gradient, and the
> >> function would return the interpolated color vector as a result.
> >> You would of course, have to write / generate 3 functions - one for the .r, .g,
> >> and .b components.
> >
> >
> >
> > Like this:
> > ...
>
>
> Waouh, impressive !!!
>
> Based on your brilliant example, here is the macro :
> // -------------------------------------------------------------------
> #macro GetColor(thisColorMap, thisEntry)
>  #local index = max(0.0, min(thisEntry, 1.0));
>
>  #local Gradient = pigment { gradient x color_map { thisColorMap } }
>  #local GradientFunction = function { pigment { Gradient } }
>
>  #local R = GradientFunction (index, 0, 0).red;
>  #local G = GradientFunction (index, 0, 0).green;
>  #local B = GradientFunction (index, 0, 0).blue;
>
>  rgb <R, G, B>
> #end
> // -------------------------------------------------------------------
>...

Hi Kurz

I don't know if it was your intention to not extract the filter and
transmit components of the color.

If you write the macro like this:


#macro GetColor(ThisColorMap, ThisEntry)

    #local Index = max(0.0, min(ThisEntry, 1.0));
    #local Gradient = pigment { gradient x color_map { ThisColorMap } }
    #local GradientFunction = function { pigment { Gradient } };
    #local Color = color GradientFunction(Index, 0, 0);

    Color

#end // macro GetColor


- then it will extract all the color components.

You'll also get a faster macro because of only one call to the pigment
function instead of three.

The value returned from the pigment function is a rgbft vector, so if all
of the components are of interest then there's no need to disassemble it
and then reassemble it.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: kurtz le pirate
Subject: Re: colors map interpolation
Date: 22 Nov 2022 11:02:51
Message: <637cf2ab$1@news.povray.org>
On 22/11/2022 13:11, Tor Olav Kristensen wrote:

> 
> Hi Kurz

Hello

> I don't know if it was your intention to not extract the filter and
> transmit components of the color.

Yes, in this case, I am not interested in the values of t and f.
I want to use the color_map as a lookup table to draw the julia sets.


> If you write the macro like this:
> 
> 
> #macro GetColor(ThisColorMap, ThisEntry)
> 
>     #local Index = max(0.0, min(ThisEntry, 1.0));
>     #local Gradient = pigment { gradient x color_map { ThisColorMap } }
>     #local GradientFunction = function { pigment { Gradient } };
>     #local Color = color GradientFunction(Index, 0, 0);
> 
>     Color
> 
> #end // macro GetColor
> 
> 
> - then it will extract all the color components.
> 
> You'll also get a faster macro because of only one call to the pigment
> function instead of three.

Well seen !
Thanks




-- 
Kurtz le pirate
Compagnie de la Banquise


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.