POV-Ray : Newsgroups : povray.general : 3.1 array bug? Server Time
16 Nov 2024 13:23:20 EST (-0500)
  3.1 array bug? (Message 1 to 4 of 4)  
From: PoD
Subject: 3.1 array bug?
Date: 24 Jul 1998 15:08:48
Message: <35B8CDA0.39CE@merlin.net.au>
POV-Ray 3.1 beta seems to have trouble initialising arrays of more than
2 dimensions.  It appears that the 'most significant' dimension index in
a 3D array is not incremented when reading the initialising data.

Here's a script which demonstrates what I'm talking about.

-----------------------------begin POV
code-----------------------------------
// This 3D array does not get initialised properly
// Only the last row is read into the array
// and the values are put where those in the first row should be ie.
A[0][0..2][0..2]
// it seems that the data are overwritten
#declare A = array[3][3][3]
{
	{
		{0,1,2},{3,4,5},{6,7,8}
	},
	{
		{9,10,11},{12,13,14},{15,16,17}
	},
	{
		{18,19,20},{21,22,23},{24,25,26}
	}
}

// uncomment the line below to initialise array
//#declare Init = on;
#ifdef(Init)
#declare I = 0; #while(I < 27)
	#declare X = mod(I,3);
	#declare Y = mod(I/3,3);
	#declare Z = mod(I/9,3);
	#declare A[Z][Y][X] = I;
	#declare I = I + 1;#end
#end

// Read the values and send them to the DEBUG stream
#declare I = 0; #while(I < 27)
	#declare X = mod(I,3);
	#declare Y = mod(I/3,3);
	#declare Z = mod(I/9,3);
	#declare N = A[Z][Y][X];
	#debug concat( "I = ",str(I,2,0),", N = ",str(N,2,0),"\n")
	#declare I = I + 1;#end
------------------------------end POV
code-----------------------------------


Cheers, PoD.


Post a reply to this message

From: John Wingfield
Subject: Re: 3.1 array bug?
Date: 28 Jul 1998 09:07:31
Message: <35BDBEE7.2AEA836B@kcl.ac.uk>
I'm having the same problem.  I need to initialise a 3 dimensional array,
and I don't really want to resort to declaring each element individually.
I've been initialising using the method quoted below.  Is this the correct
method?

Thanks

John


PoD wrote:

> POV-Ray 3.1 beta seems to have trouble initialising arrays of more than
> 2 dimensions.  It appears that the 'most significant' dimension index in
> a 3D array is not incremented when reading the initialising data.
>
> Here's a script which demonstrates what I'm talking about.
>
> -----------------------------begin POV
> code-----------------------------------
> // This 3D array does not get initialised properly
> // Only the last row is read into the array
> // and the values are put where those in the first row should be ie.
> A[0][0..2][0..2]
> // it seems that the data are overwritten
> #declare A = array[3][3][3]
> {
>         {
>                 {0,1,2},{3,4,5},{6,7,8}
>         },
>         {
>                 {9,10,11},{12,13,14},{15,16,17}
>         },
>         {
>                 {18,19,20},{21,22,23},{24,25,26}
>         }
> }
>
> // uncomment the line below to initialise array
> //#declare Init = on;
> #ifdef(Init)
> #declare I = 0; #while(I < 27)
>         #declare X = mod(I,3);
>         #declare Y = mod(I/3,3);
>         #declare Z = mod(I/9,3);
>         #declare A[Z][Y][X] = I;
>         #declare I = I + 1;#end
> #end
>
> // Read the values and send them to the DEBUG stream
> #declare I = 0; #while(I < 27)
>         #declare X = mod(I,3);
>         #declare Y = mod(I/3,3);
>         #declare Z = mod(I/9,3);
>         #declare N = A[Z][Y][X];
>         #debug concat( "I = ",str(I,2,0),", N = ",str(N,2,0),"\n")
>         #declare I = I + 1;#end
> ------------------------------end POV
> code-----------------------------------
>
> Cheers, PoD.


Post a reply to this message

From: Pan
Subject: beta 5 Re: 3.1 array bug?
Date: 28 Jul 1998 17:03:51
Message: <35be2ea7.0@news.povray.org>
beta 5 is now out at www.povray.org, but
the array bug is not fixed


Post a reply to this message

From: PoD
Subject: Re: 3.1 array bug?
Date: 28 Jul 1998 17:16:15
Message: <35BE3161.665E@merlin.net.au>
As far as I can tell from the docs and the way 2D arrays work, the
initialising at the top of the included pov code should work.  The only
way around the initialisation problem that I can see at the moment would
be to use the file io routines, something like :

#open File "Myfile.txt" read
#read (File, XDim,YDim,ZDim)
#declare Array = array[XDim][YDim][ZDim]
#declare X = 0; #while(X < XDim)
  #declare Y = 0; #while(Y < YDim)
    #declare Z = 0; #while(Z < ZDim)
      #read(File, Value)
      #declare Array[X][Y][Z] = Value;
      #declare Z = Z + 1; #end
    #declare Y = Y + 1; #end
  #declare X = X + 1; #end
#close File

Note: this is untested at the moment but it should work, hope it helps.

Cheers, PoD.

John Wingfield wrote:
> 
> I'm having the same problem.  I need to initialise a 3 dimensional array,
> and I don't really want to resort to declaring each element individually.
> I've been initialising using the method quoted below.  Is this the correct
> method?
> 
> Thanks
> 
> John
> 
> PoD wrote:
> 
> > POV-Ray 3.1 beta seems to have trouble initialising arrays of more than
> > 2 dimensions.  It appears that the 'most significant' dimension index in
> > a 3D array is not incremented when reading the initialising data.
> >
> > Here's a script which demonstrates what I'm talking about.
> >
> > -----------------------------begin POV
> > code-----------------------------------
> > // This 3D array does not get initialised properly
> > // Only the last row is read into the array
> > // and the values are put where those in the first row should be ie.
> > A[0][0..2][0..2]
> > // it seems that the data are overwritten
> > #declare A = array[3][3][3]
> > {
> >         {
> >                 {0,1,2},{3,4,5},{6,7,8}
> >         },
> >         {
> >                 {9,10,11},{12,13,14},{15,16,17}
> >         },
> >         {
> >                 {18,19,20},{21,22,23},{24,25,26}
> >         }
> > }
> >
> > // uncomment the line below to initialise array
> > //#declare Init = on;
> > #ifdef(Init)
> > #declare I = 0; #while(I < 27)
> >         #declare X = mod(I,3);
> >         #declare Y = mod(I/3,3);
> >         #declare Z = mod(I/9,3);
> >         #declare A[Z][Y][X] = I;
> >         #declare I = I + 1;#end
> > #end
> >
> > // Read the values and send them to the DEBUG stream
> > #declare I = 0; #while(I < 27)
> >         #declare X = mod(I,3);
> >         #declare Y = mod(I/3,3);
> >         #declare Z = mod(I/9,3);
> >         #declare N = A[Z][Y][X];
> >         #debug concat( "I = ",str(I,2,0),", N = ",str(N,2,0),"\n")
> >         #declare I = I + 1;#end
> > ------------------------------end POV
> > code-----------------------------------
> >
> > Cheers, PoD.


Post a reply to this message

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