POV-Ray : Newsgroups : povray.advanced-users : function select logic Server Time
19 Apr 2024 08:22:20 EDT (-0400)
  function select logic (Message 11 to 17 of 17)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: clipka
Subject: Re: function select logic
Date: 23 Nov 2016 17:18:35
Message: <583615bb$1@news.povray.org>
Am 23.11.2016 um 21:50 schrieb Mike Horvath:
> On 11/23/2016 12:19 PM, Bald Eagle wrote:
>> #declare LimitRange = function (Number) {
>>  select (Number,      // Input
>>  666,        // special flag value for values less than zero
>>  select (1-Number, 666, Number)  // second select operation
>>  )        // 1 - 0 = 1
>> }         // 1 - 1 = 0
>>          // 1 - 1.1 = - 0.1
>>          // so using (1 - Number) then filters out numbers greater than 1
>> #for (Number, -1, 2, 0.5)
>>  #declare Result = LimitRange (Number);
>>  #debug concat( "Number = ", str(Number, 3, 1),  "     Result = ",
>> str(Result,
>> 3, 1), "\n")
>> #end
> 
> Can this be used to generate an isosurface? Will the 666 break an
> isosurface?

Don't listen to that man.

Isosurfaces need contiguous functions, and the key to "discarding" some
set of coordinates from an isosurface is via the threshold.

You want to find a function f(x,y,z) and a threshold T so that
f(x,y,z)<T if all of R, G and B are within the range 0..1, f(x,y,z)>T if
any is outside that range, and f(x,y,z)=0 if any is exactly on a border
of the range. You also want f(x,y,z) to increase reasonably steadily
near the borders.

In other words, you need a function that gives you a kind of estimate
how close you are to the border, with f<T indicating that you are on the
inside, f>T that you are on the outside.

If you only had R and the upper bound of 1 to worry about, the task
would be easy-peasy: All you'd need is a threshold, and a reasonably
smooth function that is below that threshold for inside points, and
above the threshold for outside points. You already have that:

    T = 1
    f(x,y,z) = R(x,y,z)

If you only had R and the lower bound of 0 to worry about, the task is
also not too difficult: Again you already have a threshold; the function
R won't fit as-is though, as it would be below the threshold outside,
and above the threshold inside. But that can easily be fixed:

    T = 0
    f(x,y,z) = -R(x,y,z)

However, if you have to worry about both the upper and lower bound, you
need a function that "dips" below the threshold between the bounds; The
mathematical absolute is a good basis for this; for example, the
following would test for the bounds -1 and 1:

    T = 1
    f(x,y,z) = abs(R(x,y,z))

This doesn't perfectly fit your problem, as the lower bound is wrong.
Now we don't have any trivial single operation that could fix that, but
changing the threshold will change the total width of the interval while
keeping its center unaffected, and adding a constant to the abs()
parameter will change the center while keeping its total width
unaffected. So after some deliberation, we'll end up with:

    T = 0.5
    f(x,y,z) = abs(R(x,y,z)-0.5)

At R=0 this evaluates to:

    f = abs(0-0.5) = abs(-0.5) = 0.5 = T

and at R=1 it evaluates to:

    f = abs(1-0.5) = abs(0.5) = 0.5 = T


Now that we have figured out how to test for R being inside the bounds,
we can move on to G and B: Obviously the basic principle is the same, so
all we need to figure out is how to combine the three:

    T = 0.5
    fR(x,y,z) = abs(R(x,y,z)-0.5)
    fG(x,y,z) = abs(G(x,y,z)-0.5)
    fB(x,y,z) = abs(B(x,y,z)-0.5)

We need to find a single function f(x,y,z) so that f<T if all of
fR,fG,fB are smaller than T, but f>T if any is larger than T.

It turns out that max(fR,fG,fB) should give us exactly that. So we end
up with:

    T = 0.5
    f(x,y,z) = max (
      abs(R(x,y,z)-0.5),
      abs(G(x,y,z)-0.5),
      abs(B(x,y,z)-0.5)
    )


Post a reply to this message

From: Mike Horvath
Subject: Re: function select logic
Date: 23 Nov 2016 17:53:04
Message: <58361dd0$1@news.povray.org>
On 11/23/2016 5:17 PM, clipka wrote:
> If you only had R and the upper bound of 1 to worry about, the task
> would be easy-peasy: All you'd need is a threshold, and a reasonably
> smooth function that is below that threshold for inside points, and
> above the threshold for outside points. You already have that:
>
>     T = 1
>     f(x,y,z) = R(x,y,z)
>

Unfortunately, my R(x,y,z), G(x,y,z) and B(x,y,z) are not producing a 
visible shape.

Only 1-R(x,y,z), 1-G(x,y,z) and 1-B(x,y,z) are doing so, and they all 
look identical for some reason.

:(


Mike


Post a reply to this message

From: Mike Horvath
Subject: Re: function select logic
Date: 23 Nov 2016 18:28:42
Message: <5836262a$1@news.povray.org>
On 11/23/2016 1:59 AM, Mike Horvath wrote:
> I have the following three functions:
>
> #declare correctRGB_R = function(R,G,B) {min(max(R,0),1)}
> #declare correctRGB_G = function(R,G,B) {min(max(G,0),1)}
> #declare correctRGB_B = function(R,G,B) {min(max(B,0),1)}
>
> They each process input and output one component of an R,G,B color vector.
>
> However, instead of the above, I want the entire vector discarded if
> *any* of R, G or B is less than zero or greater than one.
>
> I'm not sure how to form the select statement. What is the best way to
> do this?
>
> Mike

Here is the code I came up with:

// utility
#declare selectRGBa = function(C,D) {select(C,0,D)}
#declare selectRGBb = function(C,D) {select(C-1,D,D,0)}


// input R: between 0 and 1
// input G: between 0 and 1
// input B: between 0 and 1
// output R: between 0 and 1
// output G: between 0 and 1
// output B: between 0 and 1
#declare correctRGBa1 = function(R,G,B) 
{selectRGBa(R,selectRGBa(G,selectRGBa(B,R)))}
#declare correctRGBa2 = function(R,G,B) 
{selectRGBa(R,selectRGBa(G,selectRGBa(B,G)))}
#declare correctRGBa3 = function(R,G,B) 
{selectRGBa(R,selectRGBa(G,selectRGBa(B,B)))}
#declare correctRGBb1 = function(R,G,B) 
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa1(R,G,B))))}
#declare correctRGBb2 = function(R,G,B) 
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa2(R,G,B))))}
#declare correctRGBb3 = function(R,G,B) 
{selectRGBb(R,selectRGBb(G,selectRGBb(B,correctRGBa3(R,G,B))))}

The selectRGBa and selectRGBb functions are new helper functions.

Mike


Post a reply to this message

From: clipka
Subject: Re: function select logic
Date: 23 Nov 2016 18:39:51
Message: <583628c7$1@news.povray.org>
Am 24.11.2016 um 00:28 schrieb Mike Horvath:
> On 11/23/2016 1:59 AM, Mike Horvath wrote:
>> I have the following three functions:
>>
>> #declare correctRGB_R = function(R,G,B) {min(max(R,0),1)}
>> #declare correctRGB_G = function(R,G,B) {min(max(G,0),1)}
>> #declare correctRGB_B = function(R,G,B) {min(max(B,0),1)}
>>
>> They each process input and output one component of an R,G,B color
>> vector.
>>
>> However, instead of the above, I want the entire vector discarded if
>> *any* of R, G or B is less than zero or greater than one.
>>
>> I'm not sure how to form the select statement. What is the best way to
>> do this?
>>
>> Mike
> 
> Here is the code I came up with:

And do you have any idea what it actually does? ;)
Because I have a hunch you're still struggling with the basic concepts
you're trying to employ.

My recommendation would be to toy around with the isosurface tutorial a
bit, to get a better understanding of what isosurfaces actually do,
before you try to apply them to your problem.


Post a reply to this message

From: Mike Horvath
Subject: Re: function select logic
Date: 23 Nov 2016 19:20:27
Message: <5836324b$1@news.povray.org>
On 11/23/2016 6:39 PM, clipka wrote:
> And do you have any idea what it actually does? ;)
> Because I have a hunch you're still struggling with the basic concepts
> you're trying to employ.
>
> My recommendation would be to toy around with the isosurface tutorial a
> bit, to get a better understanding of what isosurfaces actually do,
> before you try to apply them to your problem.
>

No I don't. In fact I don't understand why a parametric wouldn't work 
better. Except that it is limited to u and v, whereas I need a third 
parameter L.

But you said isosurfaces were the way to go.


Mike


Post a reply to this message

From: clipka
Subject: Re: function select logic
Date: 23 Nov 2016 20:16:45
Message: <58363f7d@news.povray.org>
Am 24.11.2016 um 01:20 schrieb Mike Horvath:
> On 11/23/2016 6:39 PM, clipka wrote:
>> And do you have any idea what it actually does? ;)
>> Because I have a hunch you're still struggling with the basic concepts
>> you're trying to employ.
>>
>> My recommendation would be to toy around with the isosurface tutorial a
>> bit, to get a better understanding of what isosurfaces actually do,
>> before you try to apply them to your problem.
>>
> 
> No I don't. In fact I don't understand why a parametric wouldn't work
> better. Except that it is limited to u and v, whereas I need a third
> parameter L.
> 
> But you said isosurfaces were the way to go.

Yes. Because parametrics are kind of the other way round.

In isosurfaces, you use a function that maps 3D space to something.

In parametrics, you use a set of functions that map something to 3D space.


In the isosurface approach to your problem, you basically design a
function that performs the mapping

    3D cartesian -> Lch -> RGB -> "distance" to boundaries

and let the isosurface iterate over 3D space to find the points that
fall inside valid RGB space.


In the parametrics approach to your problem, you basically design a
family of functions that perform the mapping

    RGB -> Lch -> 3D cartesian

and let a set of six(!) parametrics iterate over two dimensions of RGB
space (RG, RB and GB, respectively), with the third dimension set to one
of the limits (0 or 1, respectively) to find out where those faces end
up in 3D space.


You may note that the isosurface approach will give you a volume, and is
therefore fully suited for use in CSG, whereas the parametrics approach
will give you surfaces only, and therefore will only work properly in
unions.


Post a reply to this message

From: scott
Subject: Re: function select logic
Date: 24 Nov 2016 03:04:09
Message: <58369ef9$1@news.povray.org>
>> What do you mean by discarded? A function must always return a value,
>> there is no "discarded" option. Where/how are you going to use these
>> three functions and what do you want the final result to be if the input
>> RGB is out of range? You could return a special value like -1 to
>> indicate a "discarded" vector - but it depends what you're going to do
>> next with the result.
>>
>
> It's for an isosurface, actually, not a color. It just so happens I'm
> modeling a color solid. So color = shape. Sorry.
>
> When any of R, G or B are outside the range 0..1, then I do not want it
> to be part of the shape. I think a select statement can do this.

Ignore all our guesses then as to what you wanted - clipka already 
posted what you should do.


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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