POV-Ray : Newsgroups : povray.advanced-users : about #fopen and read from a list Server Time
25 Dec 2024 21:26:19 EST (-0500)
  about #fopen and read from a list (Message 1 to 2 of 2)  
From: ferrari
Subject: about #fopen and read from a list
Date: 14 Jun 2006 16:10:00
Message: <web.44906cb6d2fc92522e10ed0e0@news.povray.org>
hello, I am using #fopen and (#read) to read data from a list of this form:

1;
0.4;
4;
2.34;
5.67;
2.11;
etc...

I need to assign each value for the next frame in an animation.

1;    for frame 1
0.4;   for frame 2
4;    for frame 3
2.34;   for frame 4
5.67;   for frame 5
2.11;   for frame 6.....etc...

I use this code:

#declare Dur=3000;
#fopen Muestreo1 "muestreoc5-pd1.txt" read
#declare Fm1=0;
#declare Frames1=0;
Declare_From(Fm1,0)
#while(Frames1<(Dur))
#read (Muestreo1,S1)
Declare_To(Fm1,(Frames1)/Dur,S1)
#declare Frames1=Frames1+1;
#end

where:
Dur is the dur in frames of the anim.
Fm1 is the name of value
S1 is the value of the "next value" in the list of textfile.
this works fine but I don`t sure if this is the most efficient...
there is some other way to do it??????

thanks a lot!!!


Post a reply to this message

From: Tim Attwood
Subject: Re: about #fopen and read from a list
Date: 27 Jun 2006 01:24:25
Message: <44a0c109$1@news.povray.org>
This method shaved off about 5% overall time when I ran a test of 1000 
entries with minimal scenes..

#declare Start_Frame = 0;
#declare End_Frame = 999;

#if (clock = Start_Frame)

// read in values
   #local A_Value = 0;
   #declare BigArray = array[(End_Frame+1)-Start_Frame];

   #fopen FileHandle1 "vals_test.txt" read

   #local Count = 0;
   #while (Count<=End_Frame)
      #read (FileHandle1,A_Value)
      #declare BigArray[Count] = A_Value;
      #local Count = Count + 1;
   #end
   #fclose FileHandle1

// write an inc file
   #fopen FileHandle2 "vals_test.inc" write
   #local Count = 0;
   #write (FileHandle2,"#switch (clock)\n")
   #while (Count<=End_Frame)
      #write (FileHandle2,concat ("   #case (",str(Count,2,0),")\n") )
      #write (FileHandle2,concat ("   #declare 
List_Value=",str(BigArray[Count],2,2)";\n") )
      #write (FileHandle2,"   #break\n")
      #local Count = Count + 1;
   #end
   #write (FileHandle2,"#end\n")
   #fclose FileHandle2

#end

#include "vals_test.inc"


Post a reply to this message

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