|
![](/i/fill.gif) |
> I would like to read data (float or vectors of float) from an ascii file and use
> the data as coordinates for the geometry in the scene: some spheres connected by
> cylinders.
>
> I tried with the following code and an input file with a sequence of floats.
> The problem is that some data in the input file are not read (I checked with the
> #write): sometimes every second float is read, sometimes there is no regular
> pattern. Moreover, sometimes the minus sign is not read.
> (I got a similar error with vectors of floats)
>
> Am I doing something wrong or is there a bug in the I/O functions?
>
> I'm using povray-3.6.1-12 on ubuntu 9.04 but I get the same error in windows
> both with 3.6.1 and 3.6.2.
>
> Thanks
> Ester
>
> #fopen inputfile "in.dat" read
> //#fopen outputfile "out.dat" write
>
> #if (defined(inputfile))
> #read (inputfile, y1, y2, y3)
> #end
>
> #while (defined(inputfile))
> #declare x1 = y1;
> #declare x2 = y2;
> #declare x3 = y3;
>
> #read (inputfile, y1,y2,y3)
>
> sphere { <x1,x2,x3>, 0.3 pigment {color Green}}
> #if (!(x1 = y1 & x2 = y2 & x3 = y3))
> cylinder { <x1,x2,x3>, <y1,y2,y3>, 0.1 pigment {color Red}}
> #end
>
> // #write (outputfile, x1, " ", x2, " ", x3, "\n")
> #end
>
> #fclose inputfile
> //#fclose outputfile
>
>
Make sure that your file is comma separated. You don't always need the
comma if all the values are positive, but you absolutely need them
before any negative value.
Whenever you get a negative value preceded by a float or a vector, the
negative value get substracted from the preceding one.
Normaly, <1 2 3><4 5 6, 7> is read correctly as a 3D and a 4D vectors,<1
2 3>4.56 as a 3D vector and a float and 1.23 4.56 as two floats.
BUT!
17 -5 becomes 12
<12, 5, 9> -8 becomes <4, -3, 1>
100 -5 -33 becomes 62
Alain
Post a reply to this message
|
![](/i/fill.gif) |