POV-Ray : Newsgroups : povray.general : Array of points for use with bicubic patch Server Time
29 Jul 2024 18:27:28 EDT (-0400)
  Array of points for use with bicubic patch (Message 11 to 15 of 15)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: D103
Subject: Re: Array of points for use with bicubic patch
Date: 5 May 2011 09:00:01
Message: <web.4dc29e162d1676e45ae2687f0@news.povray.org>
"D103" <nomail@nomail> wrote:
> #declare X1=-1.5;  //in the scene file these are equal to the v_length of the
> appropriate values.
> #declare Z1=-1.5;
> #declare Cnt=0;
>
> #while(X1<=1.5)
>   #while(Z1<=1.5)
>     #if(Cnt>=15)
>       #debug "Cnt = illegal value.\n"
>     #else
>       #debug "Cnt is within legal range.\n"
>     #end
>     //#declare Pts[Cnt]=<X1, 0, Z1>;
>     sphere { 0, 0.1 pigment { White } translate <X1, 0, Z1> }
>     #declare Z1=Z1+1;
>     #declare Cnt=Cnt+1;
>   #end
>
> For some reason, when I run this in POV-Ray, it only creates one sphere, (or
> else several spheres in the same location), and when the sphere is replace with
> an array, the first point is generated alright, but on the second loop, it
> produces an error message: "attempt to access uninitialized array element".
>   #declare X1=X1+1;
>   #declare Z1=-1.5;
> #end

Not quite sure what went wrong there, but this seems to have fixed it:

#declare S1 = seed(7);
#declare S2 = seed(rand(S1)*10);

#macro RandColour(Col)
  colour Col+(<rand(S1), rand(S1), rand(S1)>-0.5)
  #if (1<(Col.gray))
    #local Col=Col-(<rand(S2), rand(S2), rand(S2)>);
    #else
      #if (0>(Col.gray))
      #local Col=Col+(<rand(S2), rand(S2), rand(S2)>);
    #end
  #end
#end

(thought I might as well post this macro, in case someone wants it)

#declare S3=seed(3);
#declare Cnt=0;
#declare X=-1.5;
#declare Z=-1.5;

#declare Pts = array[16];
#while(X<=1.5)
  #while(Z<=1.5)
    #if(Cnt>15)
      #debug "Cnt = illegal value.\n"
    #else
      #debug "Cnt is within legal range.\n"
    #end
    #declare Y=sin(X*4)/2;
    #declare Pts[Cnt]=<X, Y, Z>;
    #declare Z=Z+1;
    #declare Cnt=Cnt+1;
  #end
  #declare X=X+1;
  #declare Z=-1.5;
#end

bicubic_patch {
  type 1 u_steps 3 v_steps 3
  #declare C=0;
  #while(C<=15)
    Pts[C]
    #declare C=C+1;
  #end
  pigment {
    ripples colour_map {
      #declare Ind = 0;
      #declare Num = 50;
      #declare Rand = rand(S3);
      #while(Ind<=Num)
        #if(Rand<(1/3))
          [Ind/Num RandColour(Yellow) ]
        #end
        #if(Rand>(1/3)&Rand<(2/3))
          [Ind/Num RandColour(Cyan) ]
        #end
        #if(Rand>(2/3)&Rand<(1))
          [Ind/Num RandColour(Magenta) ]
        #end
      #declare Ind = Ind + 1;
      #end
    }
  }
}

Perhaps someone can shed some light on what's going on?

Thanks,
D103


Post a reply to this message

From: D103
Subject: Re: Array of points for use with bicubic patch
Date: 5 May 2011 09:05:00
Message: <web.4dc2a00d2d1676e45ae2687f0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
> D103 <nomail@nomail> wrote:
> > #declare X1=-1.5;  //in the scene file these are equal to the v_length of the
> > appropriate values.
> > #declare Z1=-1.5;
> > #declare Cnt=0;
>
> > #while(X1<=1.5)
> >   #while(Z1<=1.5)
> >     #if(Cnt>=15)
> >       #debug "Cnt = illegal value.\n"
> >     #else
> >       #debug "Cnt is within legal range.\n"
> >     #end
> >     //#declare Pts[Cnt]=<X1, 0, Z1>;
> >     sphere { 0, 0.1 pigment { White } translate <X1, 0, Z1> }
> >     #declare Z1=Z1+1;
> >     #declare Cnt=Cnt+1;
> >   #end
> >   #declare X1=X1+1;
> >   #declare Z1=-1.5;
> > #end
>
>   You seem to have very complicated ways of performing nested loops.
> What's wrong with the traditional way of doing nested loops? In other
> words:
>
> #declare Cnt = 0;
> #declare X1 = -1.5;
> #while(X1 <= 1.5)
>   #declare Z1 = -1.5;
>   #while(Z1 <= 1.5)
>
>     ...
>
>     #declare Z1 = Z1 + 1;
>     #declare Cnt = Cnt + 1;
>   #end
>   #declare X1 = X1 + 1;
> #end
>
> --
>                                                           - Warp

Sorry, afraid I'm in the dark here. Perhaps you could explain in a bit more
detail? I've read the help files on nested loops, maybe there's something I
missed or misunderstood.

Thank you very much.

D103


Post a reply to this message

From: Warp
Subject: Re: Array of points for use with bicubic patch
Date: 5 May 2011 12:33:47
Message: <4dc2d16b@news.povray.org>
D103 <nomail@nomail> wrote:
> > #declare Cnt = 0;
> > #declare X1 = -1.5;
> > #while(X1 <= 1.5)
> >   #declare Z1 = -1.5;
> >   #while(Z1 <= 1.5)
> >
> >     ...
> >
> >     #declare Z1 = Z1 + 1;
> >     #declare Cnt = Cnt + 1;
> >   #end
> >   #declare X1 = X1 + 1;
> > #end
> >
> > --
> >                                                           - Warp

> Sorry, afraid I'm in the dark here. Perhaps you could explain in a bit more
> detail? I've read the help files on nested loops, maybe there's something I
> missed or misunderstood.

  I just can't understand why you insist in writing nested loops in such
complicated ways rather than using the simpler approach, as shown above.

-- 
                                                          - Warp


Post a reply to this message

From: Alain
Subject: Re: Array of points for use with bicubic patch
Date: 5 May 2011 14:18:53
Message: <4dc2ea0d@news.povray.org>

> Warp<war### [at] tagpovrayorg>  wrote:
>> D103<nomail@nomail>  wrote:
>>> #declare X1=-1.5;  //in the scene file these are equal to the v_length of the
>>> appropriate values.
>>> #declare Z1=-1.5;
>>> #declare Cnt=0;
>>
>>> #while(X1<=1.5)
>>>    #while(Z1<=1.5)
>>>      #if(Cnt>=15)
>>>        #debug "Cnt = illegal value.\n"
>>>      #else
>>>        #debug "Cnt is within legal range.\n"
>>>      #end
>>>      //#declare Pts[Cnt]=<X1, 0, Z1>;
>>>      sphere { 0, 0.1 pigment { White } translate<X1, 0, Z1>  }
>>>      #declare Z1=Z1+1;
>>>      #declare Cnt=Cnt+1;
>>>    #end
>>>    #declare X1=X1+1;
>>>    #declare Z1=-1.5;
>>> #end
>>
>>    You seem to have very complicated ways of performing nested loops.
>> What's wrong with the traditional way of doing nested loops? In other
>> words:
>>
>> #declare Cnt = 0;
>> #declare X1 = -1.5;
>> #while(X1<= 1.5)
>>    #declare Z1 = -1.5;
>>    #while(Z1<= 1.5)
>>
>>      ...
>>
>>      #declare Z1 = Z1 + 1;
>>      #declare Cnt = Cnt + 1;
>>    #end
>>    #declare X1 = X1 + 1;
>> #end
>>
>> --
>>                                                            - Warp
>
> Sorry, afraid I'm in the dark here. Perhaps you could explain in a bit more
> detail? I've read the help files on nested loops, maybe there's something I
> missed or misunderstood.
>
> Thank you very much.
>
> D103
>
>

When making nested loops, it's normaly beter to initiate any inner loop 
counter just before it's #while statement.

You initiate your counter first outside the outer loop. Then, you 
reinitiate that counter for the next iteration after the #end of the 
loop and after you increment the outer loop's counter.

The usual way is:
Initiate the outer loop's counter.
Start the outer loop.
possibly do some stuff.

Initiate the iner loop's counter.
Start the inner loop.
Do the iner loop's stuf and counter incrementation.
Close the iner loop.

possibly do some other outer loop stuff.
Increment the outer loop's counter.
Close the outer loop.

This is much cleaner as the iner loop is initiated just before the place 
where it's used.
You only need to initialise the iner loop in one place.
You can use a #local variable for the iner loop instead of one that is 
global. It reduces the risks of name collision and undesirable side effects.



Alain


Post a reply to this message

From: D103
Subject: Re: Array of points for use with bicubic patch
Date: 6 May 2011 09:45:01
Message: <web.4dc3fa362d1676e45ae2687f0@news.povray.org>
Alain <aze### [at] qwertyorg> wrote:
.....
>
> When making nested loops, it's normaly beter to initiate any inner loop
> counter just before it's #while statement.
>
> You initiate your counter first outside the outer loop. Then, you
> reinitiate that counter for the next iteration after the #end of the
> loop and after you increment the outer loop's counter.
>
> The usual way is:
> Initiate the outer loop's counter.
> Start the outer loop.
> possibly do some stuff.
>
> Initiate the iner loop's counter.
> Start the inner loop.
> Do the iner loop's stuf and counter incrementation.
> Close the iner loop.
>
> possibly do some other outer loop stuff.
> Increment the outer loop's counter.
> Close the outer loop.
>
> This is much cleaner as the iner loop is initiated just before the place
> where it's used.
> You only need to initialise the iner loop in one place.
> You can use a #local variable for the iner loop instead of one that is
> global. It reduces the risks of name collision and undesirable side effects.
>
>
>
> Alain

Ah. I don't know why I didn't understand before.
Oh well, better late than never.

Thanks guys,
D103


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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