POV-Ray : Newsgroups : povray.binaries.animations : Uberpov persistent feature for animation of big scene Server Time: 26 Feb 2021 21:48:57 GMT
  Uberpov persistent feature for animation of big scene (Message 5 to 14 of 14)  
<<< Previous 4 Messages Goto Initial 10 Messages
From: Kenneth
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 7 Jan 2018 05:40:00
Message: <web.5a51b2006e53ffa4a47873e10@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

>
> I presume you mean something like this:
>
>     #ifndef(MyBigFatUnion)
>       #define Blah = ...
>       #define Dunno = ...
[clip]

Uh... #define? I couldn't find that in the docs. A UNIX thing maybe??

I'm guessing that you mean...

#ifndef(MyBigFatUnion)
#declare Blah = ...
#declare Dunno = ...

I do see what you mean, though-- that the #declare-d things (#declared within
the #ifndef block) need to come *before* the #persistent union{...} of those
things.

I was somehow thinking that the following kind of construct would work instead,
and still be 'persistent' (although it's a strange example, I admit-- I wouldn't
normally put #declares within a union)...

#ifndef(FOO)
#persistent FOO =
union{
#declare TEX_1 = texture{...}
#declare MY_BOX = box{0,1}
object{MY_BOX texture{TEX_1}
....similar stuff...
....
#end

object{FOO}

My guess is that the inner #declares are NOT 'persistent', even though they are
wrapped in a #persistent block. (Assuming that my crazy union even works at
all!!)


Post a reply to this message

From: clipka
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 7 Jan 2018 09:39:47
Message: <5a51eae3$1@news.povray.org>
Am 07.01.2018 um 06:37 schrieb Kenneth:

> Uh... #define? I couldn't find that in the docs. A UNIX thing maybe??

A C/C++ thing. It's a miracle I'm not mixing it up with POV-Ray's
`#declare' more often.

> I was somehow thinking that the following kind of construct would work instead,
> and still be 'persistent' (although it's a strange example, I admit-- I wouldn't
> normally put #declares within a union)...
> 
> #ifndef(FOO)
> #persistent FOO =
> union{
> #declare TEX_1 = texture{...}
> #declare MY_BOX = box{0,1}
> object{MY_BOX texture{TEX_1}
> .....similar stuff...
> .....
> #end
> 
> object{FOO}
> 
> My guess is that the inner #declares are NOT 'persistent', even though they are
> wrapped in a #persistent block. (Assuming that my crazy union even works at
> all!!)

It should work fine as well.

The inner `#declare`s are indeed not persistent; however, their content
(or, more precisely, a copy thereof) is inserted into a union that /is/
persistent.

If it helps understand the concept, you might think of `#persistent` as
a "super-global" equivalent of `#declare`.

Take a look at the following macro, and compare it to your code:

    #macro MyMacro()
      #ifndef(FOO)
      #declare FOO =
        union {
          #local TEX_1 = texture{...}
          #local MY_BOX = box{0,1}
          object{MY_BOX texture{TEX_1}
          ...
        }
      #end
      object{FOO}
    #end

Note how this assembles a union from local variables (which "die" each
time the end of the macro is reached), and assigns the resulting object
to a global variable, which will still be "alive" if the macro is
invoked again later.

Now just like a macro's local variables "die" each time the end of the
macro is reached, but their contents can "survive" into the next macro
invocation if plugged into a global variable, so do global variables
"die" each time the "end of the frame" is reached, but their contents
can "survive" into the next frame if plugged into a persistent variable.


Post a reply to this message

From: Kenneth
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 7 Jan 2018 20:10:01
Message: <web.5a527e686e53ffa4a47873e10@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
>
> Take a look at the following macro, and compare it to your code:
>
>     #macro MyMacro()
>       #ifndef(FOO)
>       #declare FOO =
>         union {
>           #local TEX_1 = texture{...}
>           #local MY_BOX = box{0,1}
>           object{MY_BOX texture{TEX_1}
>           ...
>         }
>       #end
>       object{FOO}
>     #end
>
> Note how this assembles a union from local variables (which "die" each
> time the end of the macro is reached), and assigns the resulting object
> to a global variable, which will still be "alive" if the macro is
> invoked again later.
>

I never realized that a macro's result-- object(FOO)-- was a global variable
that remained 'alive' in a scene once the macro was invoked. Is that
specifically because #ifndef is used here? (Actually, I'm guessing that it has
nothing to do with #ifndef.)

I always thought the *entire* contents of a macro died after each use (as if
object(FOO) was always a #local thing as well.) So in effect, the result is
'cached' for use later. Very interesting!

I'm thinking of another example, just to help clarify the concept:

#macro MyMacro()
pigment{image_map{tiff "MY_IMAGE.tif"}} // a large hi-res file
#end

Same cached behavior? (i.e., is the pigment already treated as a 'global'
thing)? Or does the macro need to be like this instead:

#macro MyMacro()
#local FOO = pigment{image_map{tiff "MY_IMAGE.tif"}}
pigment{FOO}
// or maybe just FOO by itself?
#end

Sorry for getting a bit off-topic. Although I've used macros plenty of times,
there are still a few mysteries that I need to fully understand.


Post a reply to this message

From: Bald Eagle
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 7 Jan 2018 21:10:01
Message: <web.5a528b9f6e53ffa45cafe28e0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> I never realized that a macro's result-- object(FOO)-- was a global variable
> that remained 'alive' in a scene once the macro was invoked.

It has to be, since macros "spit thing out" to be used outside of the macro.

> I always thought the *entire* contents of a macro died after each use (as if
> object(FOO) was always a #local thing as well.) So in effect, the result is
> 'cached' for use later. Very interesting!

I think it depends on if you use #declare or #local.

We cover this from time to time:
http://news.povray.org/povray.newusers/message/%3Cweb.5751decd76b80bcda4b712a50%40news.povray.org%3E/#%3Cweb.5751decd76
b80bcda4b712a50%40news.povray.org%3E

I'd say probably the best way to think of a macro when dealing with variables
like this, is that it's essentially just like an include file - it's just an
encapsulated piece of code.
Calling it just re-runs the code, and if it has arguments, it just uses those
new arguments.
I think the argument names and values are the only thing that are temporary,
local, and get destroyed upon exiting.


Post a reply to this message

From: clipka
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 7 Jan 2018 23:57:17
Message: <5a52b3dd$1@news.povray.org>
Am 07.01.2018 um 21:09 schrieb Kenneth:
> clipka <ano### [at] anonymousorg> wrote:
>>
>> Take a look at the following macro, and compare it to your code:
>>
>>     #macro MyMacro()
>>       #ifndef(FOO)
>>       #declare FOO =
>>         union {
>>           #local TEX_1 = texture{...}
>>           #local MY_BOX = box{0,1}
>>           object{MY_BOX texture{TEX_1}
>>           ...
>>         }
>>       #end
>>       object{FOO}
>>     #end
>>
>> Note how this assembles a union from local variables (which "die" each
>> time the end of the macro is reached), and assigns the resulting object
>> to a global variable, which will still be "alive" if the macro is
>> invoked again later.
>>
> 
> I never realized that a macro's result-- object(FOO)-- was a global variable
> that remained 'alive' in a scene once the macro was invoked. Is that
> specifically because #ifndef is used here? (Actually, I'm guessing that it has
> nothing to do with #ifndef.)

Nonono...

The first time the macro is invoked, `FOO` isn't defined yet, so the
`#ifndef(FOO)` block is entered, which contains a `#declare FOO`
statement. That statement defines a global variable named `FOO` that
sticks around even after the macro is long gone.

The `object{FOO}` is just an example statement to do _something_ with
that variable.

The second time the macro is invoked, `FOO` is already defined (because
it still sticks around from the last macro invocation), and the
`#ifndef(FOO)` block is skipped.

The `object{FOO}` again is just an example statement to do _something_
with that variable. Note that this time around it isn't using an object
created during the macro invocation itself, but rather re-uses the
object created during the first macro invocation.


The variable `FOO` persists across macro invocations regardless of
whether the `object{FOO}` statement is present or not. But without that
statement the variable would never actually be used for anything.


Post a reply to this message

From: Kenneth
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 8 Jan 2018 02:50:01
Message: <web.5a52db5e6e53ffa4a47873e10@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

>
> Nonono...
>
> The first time the macro is invoked, `FOO` isn't defined yet, so the
> `#ifndef(FOO)` block is entered, which contains a `#declare FOO`
> statement. That statement defines a global variable named `FOO` that
> sticks around even after the macro is long gone.
>
Oops, I didn't 'see' that FOO was #declared (rather than #local-ed.) Understood.
Sorry for that confusion.


Post a reply to this message

From: Kenneth
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 8 Jan 2018 02:55:00
Message: <web.5a52dd016e53ffa4a47873e10@news.povray.org>
By the way, I should have remembered some previous comments about UberPOV's
#persistent variables from here...

http://news.povray.org/povray.animations/thread/%3Cweb.565084806f515a457a3e03fe0%40news.povray.org%3E/

It's hard to keep all of this stuff in my head, but I'm trying ;-)


Post a reply to this message

From: Kenneth
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 9 Jan 2018 02:25:00
Message: <web.5a5427b66e53ffa4a47873e10@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
>
> > I never realized that a macro's result-- object(FOO)-- was a global variable
> > that remained 'alive' in a scene once the macro was invoked.
>
> It has to be, since macros "spit thing out" to be used outside of the macro.
>

Yes, I do grasp that; I think I probably wasn't being very clear with my
questions. What I meant was, I wonder if a macro can actually 'cache' its
contents for use in a scene (not for animation, but just in a regular static
scene.) An example would be this...

#macro MyMacro()
#ifndef(FOO)
#local FOO = pigment{image_map{png "MY_IMAGE.png"}} // #local, not #declare
#else
#end
pigment{FOO}
#end

#for(i,1,10000)
box{0,1
   pigment{MyMacro()}
   translate i*x
}
#end

Would this *re-load* the image_map 10,000 times into memory... or would it load
only once and 'instantiate' the image_map 9,999 times, with MUCH less memory
use? I guess I need to do an experiment to find out.


Post a reply to this message

From: clipka
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 9 Jan 2018 16:54:04
Message: <5a54f3ac$1@news.povray.org>
Am 09.01.2018 um 03:23 schrieb Kenneth:

> #macro MyMacro()
> #ifndef(FOO)
> #local FOO = pigment{image_map{png "MY_IMAGE.png"}} // #local, not #declare
> #else
> #end
> pigment{FOO}
> #end
> 
> #for(i,1,10000)
> box{0,1
>    pigment{MyMacro()}
>    translate i*x
> }
> #end
> 
> Would this *re-load* the image_map 10,000 times into memory... or would it load
> only once and 'instantiate' the image_map 9,999 times, with MUCH less memory
> use? I guess I need to do an experiment to find out.

It would load it 10,000 times; local variables are ditched after every
macro invocation.


Post a reply to this message

From: Kenneth
Subject: Re: Uberpov persistent feature for animation of big scene
Date: 10 Jan 2018 17:10:04
Message: <web.5a56479d6e53ffa4a47873e10@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

>
> It would load it 10,000 times; local variables are ditched after every
> macro invocation.

OK, that makes sense now. #Local is always 'local', regardless of the #ifndef
block. Got it. Thanks.


Post a reply to this message

<<< Previous 4 Messages Goto Initial 10 Messages

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