POV-Ray : Newsgroups : povray.advanced-users : "user-defined" isosurface Server Time
28 Jul 2024 14:30:21 EDT (-0400)
  "user-defined" isosurface (Message 4 to 13 of 13)  
<<< Previous 3 Messages Goto Initial 10 Messages
From: Warp
Subject: Re: "user-defined" isosurface
Date: 23 Jan 2006 10:06:04
Message: <43d4f0db@news.povray.org>
Leo80s <nomail@nomail> wrote:
> I shall use the isosurface command whit a user-defined function (called
> rbf)...I've defined a macro like this:

> #macro rbf (X,Y,Z)
>         calcola_w(X,Y,Z)
>         calcola_r(X,Y,Z)

>         #while (i<N)
>                 #local result=result+(w_[i]*r[i]);
>                 #local i=i+1;
>         #end
> #end
> [It's not important the body of calcola_w ad calcola_r...]

> I've writed:

>         #declare f = function(X,Y,Z) { rbf(X,Y,Z) }

  I'm not exactly sure what you are trying to do here.

  #macros are parsed and evaluated at parse time. They are a lot like the
replacement macros in C (with some differences). You can think about that
latter code as if the "rbf(...)" call was replaced with the body of the
macro. You should get a clear picture of what goes wrong.

  User-defined functions (created with the 'function' keyword) are
created at parse-time and then they exist as their own separate entities
which have nothing to so with the POV-Ray parser. The "universe" of the
user-defined function (what gets in the function after its body has been
parsed) is completely different from parse-time constructs such as #macros
and #while loops. A #while loop will not get into the user-defined function.
It can be used to build up one, but it won't get into it. It's actually a
bit difficult to explain.
  If you have ever coded C or C++, think about the difference between
a #define macro and an actual function: You can use a #define macro in
a function, but the macro is only evaluated at parse time (its call will
be replaced by its contents). No information about the macro will end in
the final binary.
  In the same way a #while loop in povray is a parse-time construct which
does not end up in the data which is used to render the scene or, as in
this case, into a use-defined function. #while loops are used to create
data, it does not get into the data.

  User-defined functions in povray are a bit tricky because their syntax,
while similar to the SDL syntax, is actually separate and different.
You can use SDL constructs to build up a function body, but it's just
that. The function body will be parsed with a completely separate parser
(which will then internally compile it to bytecode etc) *after* the SDL
constructs have been evaluated. Again, you can think about the difference
between the C preprocessor and the C compiler. It's the same kind of
difference.

  What you are apparently trying to do is to create a user-defined
function with a loop. That's not directly possible because the function
syntax does not contain loop constructs.

  Not all hope is lost, though, because user-defined functions support
recursion. You can use the select() function (to stop the recursion) and
recursive calls in order to create loops. If you have ever coded in a
functional language such as Lisp, that should be a piece of cake.

  I actually once (re)created the Mandelbrot set using recursive
user-defined functions, so it's perfectly possible.

-- 
                                                          - Warp


Post a reply to this message

From: Leo80s
Subject: Re: "user-defined" isosurface
Date: 23 Jan 2006 10:25:00
Message: <web.43d4f4b03f7154a3f20c7750@news.povray.org>
>   User-defined functions in povray are a bit tricky because their syntax,
> while similar to the SDL syntax, is actually separate and different.
> You can use SDL constructs to build up a function body, but it's just
> that. The function body will be parsed with a completely separate parser
> (which will then internally compile it to bytecode etc) *after* the SDL
> constructs have been evaluated. Again, you can think about the difference
> between the C preprocessor and the C compiler. It's the same kind of
> difference.

What do you mean with "SDL constructs"?

>
>   What you are apparently trying to do is to create a user-defined
> function with a loop. That's not directly possible because the function
> syntax does not contain loop constructs.
>
>   Not all hope is lost, though, because user-defined functions support
> recursion. You can use the select() function (to stop the recursion) and
> recursive calls in order to create loops. If you have ever coded in a
> functional language such as Lisp, that should be a piece of cake.
>
>   I actually once (re)created the Mandelbrot set using recursive
> user-defined functions, so it's perfectly possible.

Sorry for my insistence but...
1) where can I find documentation about this select construct
2) Can you send me the code where you use recursive
> user-defined functions (if it's not a problem) ?

Very very thanks
Leo


Post a reply to this message

From: Warp
Subject: Re: "user-defined" isosurface
Date: 23 Jan 2006 19:53:42
Message: <43d57a96@news.povray.org>
Leo80s <nomail@nomail> wrote:
> What do you mean with "SDL constructs"?

#declare, #while, #if, #switch, etc.

  Also keywords like object, sphere, texture, and so on are related
to the SDL and different from the user-defined function universe.

> 1) where can I find documentation about this select construct

  In the POV-Ray documentation? If you are using POV-Ray for windows,
write the word "select" (just in the scene file) and press F1.

  See also http://povray.org/documentation/view/3.6.1/228/#s02_02_01_03_04

> 2) Can you send me the code where you use recursive
> > user-defined functions (if it's not a problem) ?

#declare Factorial =
  function(A) { select(A, 1, 1, A*Factorial(A-1)) };

#declare Value = Factorial(8);
#debug concat("Factorial of 8 is ", str(Value, 0, 0), "\n")


-- 
                                                          - Warp


Post a reply to this message

From: Leo80s
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 04:25:00
Message: <web.43d5f1a63f7154a72071f7b0@news.povray.org>
thank you a lot
leo


Post a reply to this message

From: Leo80s
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 05:50:00
Message: <web.43d605983f7154a3f20c7750@news.povray.org>
> #declare Factorial =
>   function(A) { select(A, 1, 1, A*Factorial(A-1)) };
>
> #declare Value = Factorial(8);
> #debug concat("Factorial of 8 is ", str(Value, 0, 0), "n")

Hi Warp,
I tried your piece of code and it works but I need to use recursion with
element of an array...so I've modified your code in this way:

#declare w= array [10];

....[assigning integer value to w elements]

#declare Factorial =
   function(A) { select(A, 1, 1, w[A]*Factorial(A-1)) };

compiling, I've obtained this error (related on w[A]):

Parse Error: Expected 'numeric expression', undeclared identified 'A' found
instead ...

But why??? A is sure not initialited (but it's a parameter...) but why
undeclared?!?!

Leo


Post a reply to this message

From: Mike Williams
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 06:40:15
Message: <EGyC+FAiEh1DFwPq@econym.demon.co.uk>
Wasn't it Leo80s who wrote:
>> #declare Factorial =
>>   function(A) { select(A, 1, 1, A*Factorial(A-1)) };
>>
>> #declare Value = Factorial(8);
>> #debug concat("Factorial of 8 is ", str(Value, 0, 0), "n")
>
>Hi Warp,
>I tried your piece of code and it works but I need to use recursion with
>element of an array...so I've modified your code in this way:
>
>#declare w= array [10];
>
>....[assigning integer value to w elements]
>
>#declare Factorial =
>   function(A) { select(A, 1, 1, w[A]*Factorial(A-1)) };
>
>compiling, I've obtained this error (related on w[A]):
>
>Parse Error: Expected 'numeric expression', undeclared identified 'A' found
>instead ...
>
>But why??? A is sure not initialited (but it's a parameter...) but why
>undeclared?!?!

There's some info on using arrays in isosurface functions here:

http://www.econym.demon.co.uk/isotut/arrays.htm

The problem is that arrays are evaluated at parse time, and function
parameters are evaluated at render time. During the parse phase, A is
indeed undefined. 

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Leo80s
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 08:40:00
Message: <web.43d62dd03f7154a72071f7b0@news.povray.org>
> There's some info on using arrays in isosurface functions here:
>
> http://www.econym.demon.co.uk/isotut/arrays.htm

Reading this page my question is:

In your opinion, in which manner I can estimate a "reasonably small number
of elements" for an array?

thanks
leo


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 09:09:45
Message: <43d63529$1@news.povray.org>
Leo80s wrote:
>>There's some info on using arrays in isosurface functions here:
>>
>>http://www.econym.demon.co.uk/isotut/arrays.htm
> 
> Reading this page my question is:
> 
> In your opinion, in which manner I can estimate a "reasonably small number
> of elements" for an array?

Instead of continuing this 'game of cat and mouse' with helpful people 
having to guess what you need, maybe you could just say what your _goal_ 
(what do you want to create???) is rather than asking extremely specific 
questions?

Looking at this whole thread, I get the impression you are trying to do 
something with isosurfaces that they are simply not suitable for: What you 
have to understand is that isosurfaces work best with continuous functions 
due to the method used to render them (that is, the function has to be 
solved). As such, introducing large amounts of discrete values will require 
extreme settings to always get an artifact free rendering of isosurfaces.

Depending on your goal, there might actually be more suitable ways to create 
the geometry you desire with POV-Ray. But only if you let people know about 
your goal you will ever get broader, and ultimately more helpful suggestions.

	Thorsten Froehlich, POV-Team


Post a reply to this message

From: Mike Williams
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 09:20:59
Message: <XkKm2DAAWj1DFwuZ@econym.demon.co.uk>
Wasn't it Leo80s who wrote:
>> There's some info on using arrays in isosurface functions here:
>>
>> http://www.econym.demon.co.uk/isotut/arrays.htm
>
>Reading this page my question is:
>
>In your opinion, in which manner I can estimate a "reasonably small number
>of elements" for an array?

It's really up to you. Just be aware that indexing N elements requires a
minimum of N-1 "select" statements. The example on that page shows an
8-element array being indexed with 7 "select"s.

I suppose you could write an external program that would generate the
POV SDL code for as many elements as you like, or you could write those
N-1 select statements by hand. I suspect that it may not be possible to
generate the selects with a POV macro.

It's really not worth the bother anyway, because the results are likely
to be disappointing due to the infinite gradients at the
discontinuities.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Warp
Subject: Re: "user-defined" isosurface
Date: 24 Jan 2006 18:10:06
Message: <43d6b3ce@news.povray.org>
Leo80s <nomail@nomail> wrote:
> I tried your piece of code and it works but I need to use recursion with
> element of an array...so I've modified your code in this way:

  Again, you are trying to use SDL in user-defined functions, even though
I just explained that you can't do that.

  You can use SDL to *build* functions, but you can't use SDL *from*
functions. In this specific case, you can't make a function which uses
an SDL array because an array is an SDL element and user-defined functions
do not support arrays.

  It's a bummer, but it's just the way it works.

  (There's a *reason* for it to work this way, though: Unlike the SDL,
user-defined functions are internally byte-compiled, which makes their
evaluation extremely fast. I estimate that evaluating a user-defined
function is more than 10 times faster than evaluating eg. an equivalent
#macro.)

> #declare Factorial =
>    function(A) { select(A, 1, 1, w[A]*Factorial(A-1)) };

> compiling, I've obtained this error (related on w[A]):

> Parse Error: Expected 'numeric expression', undeclared identified 'A' found
> instead ...

> But why??? A is sure not initialited (but it's a parameter...) but why
> undeclared?!?!

  Because in this case "A" is not SDL and the SDL parser doesn't see it.
When you make the "w[A]" call, the SDL tries to substitute that call
with its value, but it can't because A is not defined (in the SDL level).

-- 
                                                          - Warp


Post a reply to this message

<<< Previous 3 Messages Goto Initial 10 Messages

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