POV-Ray : Newsgroups : povray.advanced-users : "user-defined" isosurface Server Time
24 Nov 2024 17:34:08 EST (-0500)
  "user-defined" isosurface (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: Leo80s
Subject: "user-defined" isosurface
Date: 23 Jan 2006 08:15:00
Message: <web.43d4d60ef96a9fb672071f7b0@news.povray.org>
hello everybody

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' hoped that using a command like this:

isosurface {
        function { rbf(x,y,z) }
        ...
}

my problem would be solved... but not: I receive a parse error in which
povray say that x,y,z seem (in the body of calcola_w) to be 3 vectors...

So I've downloaded the source code to understand how is constructed the
function provided by povray like f_torus, f_sphere, etc...

In the source code (fnintern.cpp) I've seen that internal function povided
by povray has a sintax like this:

[fnintern.cpp]
DBL f_torus(DBL *ptr, unsigned int) // 70
{
 PARAM_X = sqrt(PARAM_X * PARAM_X + PARAM_Z * PARAM_Z) - PARAM(0);
 return -PARAM(1) + sqrt(PARAM_X * PARAM_X + PARAM_Y * PARAM_Y);
}

How can I define my rbf function in order to be able to use this function to
build an isosurface???

It's very important for my graduate thesis...please answer me!!!!

Thanks
Leo


Post a reply to this message

From: Le Forgeron
Subject: Re: "user-defined" isosurface
Date: 23 Jan 2006 09:05:21
Message: <43d4e2a1@news.povray.org>
Leo80s wrote:

> I've writed:
> 
>         #declare f = function(X,Y,Z) { rbf(X,Y,Z) }
> 
> I' hoped that using a command like this:
> 
> isosurface {
>         function { rbf(x,y,z) }
>         ...
> }
> 
> my problem would be solved... but not: I receive a parse error in which
> povray say that x,y,z seem (in the body of calcola_w) to be 3 vectors...
> 

x,y and z are *RESERVED* keyword!
It seems you did not even take the time to read fully the
documentation... Start again.


> So I've downloaded the source code to understand how is constructed the
> function provided by povray like f_torus, f_sphere, etc...
> 
Stay away from the source code!

Read in details the 2.3.3.3.8 part of the windows-help...
function are evaluated at render-time, but #while and other are
evaluated at parse time (once and for all). you cannot have a
polymorphing function with #if/#while in them, you need to do it by
the math!
#local in a function is a no-no!
Your macro rbf is not doing what you might think.

> It's very important for my graduate thesis...please answer me!!!!
> 


-- 
Eifersucht ist die Leidenschaft, die mit Eifer sucht, was Leiden
schafft.

Eco: -8.75 Soc: -6.72
http://www.politicalcompass.org/


Post a reply to this message

From: Leo80s
Subject: Re: "user-defined" isosurface
Date: 23 Jan 2006 09:50:00
Message: <web.43d4ec293f7154a3f20c7750@news.povray.org>
> Read in details the 2.3.3.3.8 part of the windows-help...

what do you mean when you talk abaout "windows-help"?

> function are evaluated at render-time, but #while and other are
> evaluated at parse time (once and for all). you cannot have a
> polymorphing function with #if/#while in them, you need to do it by
> the math!

So if I can't do it by math my problem is not solvible?

> #local in a function is a no-no!

what do you mean with "no-no"?

> Your macro rbf is not doing what you might think.

thanks
leo


Post a reply to this message

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

Goto Latest 10 Messages Next 3 Messages >>>

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