POV-Ray : Newsgroups : povray.advanced-users : "user-defined" isosurface : Re: "user-defined" isosurface Server Time
28 Jul 2024 10:28:49 EDT (-0400)
  Re: "user-defined" isosurface  
From: Warp
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

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