POV-Ray : Newsgroups : povray.general : string code to load consecutive image_maps into array Server Time
31 Oct 2024 14:12:48 EDT (-0400)
  string code to load consecutive image_maps into array (Message 1 to 8 of 8)  
From: Kenneth
Subject: string code to load consecutive image_maps into array
Date: 8 Oct 2020 23:00:01
Message: <web.5f7fd17b1b75ee1bd98418910@news.povray.org>
For my recent and continuing 'city buildings' scene, I needed a way to load a
bunch of consecutively-numbered image_maps into an array. The only things that
change in the image_map titles are their numbers.  Like...

my image 1 example   (with, say, a .jpg extension)
my image 2 example
etc.

So I came up with some string-code to make the task very easy, which might be
useful to others here. (If you have already done this kind of thing previously,
please ignore-- you are smarter than I am!)

For, say, 50 different image_maps...
#declare MY_ARRAY = array[50]; // to create the initial empty array-- the index
is from zero to 49

#for(i,1,50)
#declare MY_STRING =
concat("my image"," ",str(i,0,0)," ","example.jpg")// the  i  is the re-created
image number. Note the added spaces between the extra double-quotes, to match
the image titles.
#declare MY_ARRAY[i - 1] =
pigment{image_map{jpeg MY_STRING interpolate 2}}
#end

Of course, you could further simplify the #for loop by inserting the entire
concat(...) string into the pigment itself, eliminating the
#declare MY_STRING = ...

To use an image_map later...

pigment{MY_ARRAY[27]}


Post a reply to this message

From: Kenneth
Subject: Re: string code to load consecutive image_maps into array
Date: 8 Oct 2020 23:10:00
Message: <web.5f7fd3ee29a401ccd98418910@news.povray.org>
By the way, if you are using an older version of POV-ray (prior to the #for-loop
addition), a #while loop will work just as well,


Post a reply to this message

From: jr
Subject: Re: string code to load consecutive image_maps into array
Date: 10 Oct 2020 07:05:00
Message: <web.5f81944f29a401cca8a81eb0@news.povray.org>
hi,

"Kenneth" <kdw### [at] gmailcom> wrote:
> For my recent and continuing 'city buildings' scene, I needed a way to load a
> bunch of consecutively-numbered image_maps into an array. ...
> Of course, you could further simplify the #for loop by inserting the entire
> concat(...) string into the pigment itself, eliminating the
> #declare MY_STRING = ...

or use a macro and dispense with the array altogether?!  eg.

#macro mkPigment(i_)
  pigment {image_map {jpeg concat("my image ",str(i_,0,0)," example.jpg")
interpolate 2}}
#end

(hopefully no typos)


regards, jr.


Post a reply to this message

From: Kenneth
Subject: Re: string code to load consecutive image_maps into array
Date: 10 Oct 2020 11:00:00
Message: <web.5f81cb6b29a401ccd98418910@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

>
> or use a macro and dispense with the array altogether?!  eg.
>
> #macro mkPigment(i_)
>   pigment {image_map {jpeg concat("my image ",str(i_,0,0)," example.jpg")
> interpolate 2}}
> #end
>

That's an interesting idea, and didn't occur to me. It *looks* like it would
work; now I want to test it! Gee, thanks, another test to do :-P


Post a reply to this message

From: Kenneth
Subject: Re: string code to load consecutive image_maps into array
Date: 10 Oct 2020 11:25:00
Message: <web.5f81cc6229a401ccd98418910@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

>
> #macro mkPigment(i_)
>   pigment {image_map {jpeg concat("my image ",str(i_,0,0)," example.jpg")
> interpolate 2}}
> #end
>

Oops, I just noticed the difference between this macro and my array idea-- the
macro doe not actually pre-#declare the image, whereas the array does. The main
reason for the initial  ARRAY is that it essentially #declares all of the images
at the outset-- and its main 'reason for being' is that the various images might
be used *repetitively* in a scene (which I forgot to mention!) Pre-#declaring
the images saves a tremendous amount of RAM memory later, when the array
elements are called. Their repetitions are essentially 'instances' of the
image_maps, with little to no increase in memory use.  The macro, on the other
hand, would load the image into memory every time it's invoked.

For the macro, I came up with a slight change which *might* make it work
likewise... but I don't think so:

#macro mkPigment(i_)
#declare IMG =
pigment {image_map {jpeg concat("my image ",str(i_,0,0)," example.jpg")
interpolate 2}}
IMG
#end

That would just re-#declare the image for each macro call, with the same(?)
memory increase...unless each 'newly-#declared' identical IMG just takes the
place of the previous one in memory?


Post a reply to this message

From: jr
Subject: Re: string code to load consecutive image_maps into array
Date: 10 Oct 2020 11:55:01
Message: <web.5f81d8c729a401cca8a81eb0@news.povray.org>
hi,

"Kenneth" <kdw### [at] gmailcom> wrote:
> "jr" <cre### [at] gmailcom> wrote:
> > #macro mkPigment(i_)
> > ...
>
> Oops, I just noticed the difference between this macro and my array idea-- ...
> the various images might be used *repetitively* in a scene (which I forgot to
> mention!)...

ouch, yes.  although I've followed the thread(s), I completely lost sight of the


> For the macro, I came up with a slight change which *might* make it work
> likewise... but I don't think so:
>
> #macro mkPigment(i_)
> #declare IMG =
> pigment {image_map {jpeg concat("my image ",str(i_,0,0)," example.jpg")
> interpolate 2}}
> IMG
> #end
>
> That would just re-#declare the image for each macro call, with the same(?)
> memory increase...unless each 'newly-#declared' identical IMG just takes the
> place of the previous one in memory?

not sure, would expect the old to be de-allocated.  in case it helps, the name
too could be supplied, eg:

#macro mkPigment(n_, i_)
  #local n_ = pigment {...};
#end

but wrt reducing memory, (guessing) an array will be best.


regards, jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: string code to load consecutive image_maps into array
Date: 10 Oct 2020 16:20:06
Message: <web.5f82170329a401cc1f9dae300@news.povray.org>
In this case, you can (easily) do both, since you use numbered image files.
Use the macro, but have the macro update a global array flag with the numbered
entries.
#ifdef () can check to see if an entry has been used, and if so then the macro
can just return the image_map that is already declared, else create a new
(needed) one.

Without numbered filenames, you could just compare the text filenames to see if
they've been used before.


Post a reply to this message

From: Kenneth
Subject: Re: string code to load consecutive image_maps into array
Date: 11 Oct 2020 16:20:06
Message: <web.5f83681f29a401ccd98418910@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> > [Kenneth wrote]:
> > Oops, I just noticed the difference between this macro and my array
> > idea-- ...
> > the various images might be used *repetitively* in a scene (which
> > I forgot to mention!)...
>
> ouch, yes.  although I've followed the thread(s), I completely lost sight


Your comments and posts never waste time, have no fear ;-) They always get me to
think 'outside of my own box'.


Post a reply to this message

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