POV-Ray : Newsgroups : povray.general : #read fiasco : Re: #read fiasco Server Time
11 Aug 2024 15:20:35 EDT (-0400)
  Re: #read fiasco  
From: John VanSickle
Date: 10 Aug 1999 16:40:45
Message: <37B0914C.B43E620D@erols.com>
Greg M. Johnson wrote:
> 
> John VanSickle wrote:
> 
> > Greg M. Johnson wrote:
> > >
> > > I wish that the documentation better explained the syntax for
> > > #read and #write.
> > >
> > > I have created a file of the positions and velocities of a number
> > > of particles, (34 particles at 350 time periods).  I have pasted
> > > the first four records from my file.
> >
> > Generally, when I have an outside program generate data for POV-Ray,
> > I have the same program output a standard .INC file, with all of the
> > #declares, #locals, etc., needed for POV-Ray to parse the file
> > directly. This requires very little extra effort in the program that
> > generates the data, and the results parse a lot faster.
> >
> > For instance, in my last IRTC entry, the insect parts were made of
> > bicubic patches, which I converted to meshes using a bit of macro
> > code.  I got tired of waiting for the macro to parse, so I modified
> > the macro to write the triangles to a file, in full POV syntax.
> > From then on I merely #included the generated files, in place of the
> > original generating code.  Things parsed much more quickly.

> So, like how would you make your inc if you had two variables which
> were [350][34] each?
> 
> Would your file generator literally say:
> 
> #declare position.x[1][1]=1;
> #declare position.y[1][1]=2;
> #declare position.z[1][1]=3;
> #declare position.x[1][2]=4;
> #declare position.y[1][2]=5;
> #declare position.z[1][2]=6;

No, the file generator can also dump out the following:

#declare position=array[350][34] = {
  { <1,2,3>,<4,5,6>, ... }, {... }, ...
}

The PovRay code would look like this:

// START OF SAMPLE BASIC CODE

#write(MyFile,"#declare position=array[", ROWS, "][", COLUMNS, "] = {\n")
#local iI=0; #while(iI<ROWS)
  #if (iI>0) #write(MyFile,",") #end
  #write(MyFile,"{ ")
  #local iJ=0; #while(iJ<COLUMNS)
    #if (iJ>0) #write(MyFile,",") #end
    #write(MyFile,MyDataArray[iI][iJ])
  #local iJ=iJ+1; #end
  #write(MyFile, " }\n" )
#local iI=iI+1; #end
#write(MyFile, "}\n" )

// END OF SAMPLE CODE

Your file generating program can print out the #declares, square
brackets, angle brackets, squiggly brackets, commas, and so forth.

The only difficulty is that if you want to have text data in there as
well, you have to explicitly print out the quotes with the CHR$()
function:

  #write(MyFile, "#declare MyString="; CHR$(34); "Stormbringer";
    CHR$(34); "\n")

which will create a line of text that looks like this:

  #declare MyString="Stormbringer"

You can feed a vector to the #write() directive as well; my example does.

  #write(MyFile,x-y+z*3)

will cause the string

  < 1,-1, 3>

to be written to MyFile.  There is no need to bust up the vectors into
scalars, only to build them back up later.

Of course, keeping track of the brackets and quotation marks can be
a bit of a trick. :-)

> I know how to write such a file, but wouldn't this make it a huge INC?

As you can see from my response, it will not be very much larger than
the file you already plan to use.  It might be twice as big, but that's
what we have hard drives for.

> Are you sure this is faster than reading with a #while loop the
> following data:
> 
>  1,2,3,4,5,6,

Yes, it is much faster.  The file is generated in a form the parser
already knows how to understand; the other method you discuss goes
through a #while-#end loop, which takes extra time in any interpreted
language.

Hope this helps,
John


Post a reply to this message

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