POV-Ray : Newsgroups : povray.general : How to quick filling an array Server Time
29 Dec 2024 13:37:49 EST (-0500)
  How to quick filling an array (Message 1 to 4 of 4)  
From: H  Karsten
Subject: How to quick filling an array
Date: 6 Oct 2011 19:30:00
Message: <web.4e8e3901b22b0664a3bfeb720@news.povray.org>
Hi people,

I've defined an array, like this:

#declare Detail=40;
#declare VoxelSpace=array[Detail+1][Detail+1][Detail+1];

to fill it, I did this:

#debug "Filling...\n"
#declare YI=0;
 #while (YI<Detail)
 #declare ZI=0;
 #while (ZI<Detail)
  #declare XI=0;
   #while (XI<Detail)
     #declare VoxelSpace[XI][YI][ZI]=0;
   #declare XI=XI+1;
   #end
  #declare ZI=ZI+1;
  #end
 #declare YI=YI+1;
 #end

to fill an array on initialising-time, using "Array Initializers" the docs give
me something like this:

#declare Digits =
 array[4][10]
 {
  {7,6,7,0,2,1,6,5,5,0},
  {1,2,3,4,5,6,7,8,9,0},
  {0,9,8,7,6,5,4,3,2,1},
  {1,1,2,2,3,3,4,4,5,5}
 }


Is there a way to fill an array, using only ONE line, saying that ALL values are
=0?

Best rgds,
Holger


Post a reply to this message

From: Alain
Subject: Re: How to quick filling an array
Date: 7 Oct 2011 16:07:38
Message: <4e8f5c0a@news.povray.org>

> Hi people,
>
> I've defined an array, like this:
>
> #declare Detail=40;
> #declare VoxelSpace=array[Detail+1][Detail+1][Detail+1];
>
> to fill it, I did this:
>
> #debug "Filling...\n"
> #declare YI=0;
>   #while (YI<Detail)
>   #declare ZI=0;
>   #while (ZI<Detail)
>    #declare XI=0;
>     #while (XI<Detail)
>       #declare VoxelSpace[XI][YI][ZI]=0;
>     #declare XI=XI+1;
>     #end
>    #declare ZI=ZI+1;
>    #end
>   #declare YI=YI+1;
>   #end
>
> to fill an array on initialising-time, using "Array Initializers" the docs give
> me something like this:
>
> #declare Digits =
>   array[4][10]
>   {
>    {7,6,7,0,2,1,6,5,5,0},
>    {1,2,3,4,5,6,7,8,9,0},
>    {0,9,8,7,6,5,4,3,2,1},
>    {1,1,2,2,3,3,4,4,5,5}
>   }
This can be writen on one long line.
>
>
> Is there a way to fill an array, using only ONE line, saying that ALL values are
> =0?
>
> Best rgds,
> Holger
>
>
>

You can't quick fill all element of an array using only one instruction. 
Any element must be explicitely given a content before you can get it's 
content.

As you probably don't need the indexing variables outside the 
initialisation, and you surely don't need to keep the final values, you 
can use #local.
That way, the variables will not exist once the loops are terminated.


Post a reply to this message

From: Cousin Ricky
Subject: Re: How to quick filling an array
Date: 7 Oct 2011 17:00:00
Message: <web.4e8f6738bbede7878641e0c0@news.povray.org>
Alain <aze### [at] qwertyorg> wrote:
> As you probably don't need the indexing variables outside the
> initialisation, and you surely don't need to keep the final values, you
> can use #local.
> That way, the variables will not exist once the loops are terminated.

This is true of macros and include files.  It does not apply to loops.

Try this scene file:
_________________________________________

#declare MyArray = array[5][10];
#local I = 0;
#while (I < 5)
   #local J = 0;
   #while (J < 10)
      #declare MyArray[I][J] = 0;
      #local J = J + 1;
   #end
   #local I = I + 1;
#end

text
{  ttf "cyrvetic.ttf" str(I,0,1) 0.001, 0
   translate <-1, 0.2, 2>
   pigment { rgb 1 }
   finish { ambient 1 }
}

text
{  ttf "cyrvetic.ttf" str(J,0,1) 0.001, 0
   translate <-1, -0.8, 2>
   pigment { rgb 1 }
   finish { ambient 1 }
}
_________________________________________

The identifiers I and J can be referenced even after the loops are closed.  J
can be referenced even though it's declared only inside the I loop.


Post a reply to this message

From: gregjohn
Subject: Re: How to quick filling an array
Date: 9 Oct 2011 18:30:01
Message: <web.4e921fecbbede78ce9345340@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
>
> The identifiers I and J can be referenced even after the loops are closed.  J
> can be referenced even though it's declared only inside the I loop.


Wow, that's surprising. How would #declare and #local be different in "keeping
things around"?


Post a reply to this message

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