POV-Ray : Newsgroups : povray.general : comma separated value file for data input : Re: comma separated value file for data input Server Time
8 May 2024 16:48:42 EDT (-0400)
  Re: comma separated value file for data input  
From: Tim Attwood
Date: 10 Feb 2007 04:25:42
Message: <45cd8f96$1@news.povray.org>
> Although far from new to POV-Ray (programmed first rendering in about 
> 1996),
> I am an infrequent user and thus a novice.  Right now I'm returning to it 
> to
> produce some 3D statistical graphs.  It would be really convenient for me
> read data in from some sort of two-dimensional data file (a table).  Comma
> separated value files (.CSV) are commonly used for this.

Pov can #read values from a file delimited by commas, these values
should be valid numbers, vectors, or strings. Strings should be inside
quotes. Vectors should be pov style <#,#,#>. Trailing commas are
expected. Files are opened with #fopen. Reading past the end of a
file automatically closes it, but #fclose them...
(3.2.2.3  File I/O Directives)

>... Is there any convenient way to read a CSV file into some sort of
> data container (an array of arrays? ...

Pov supports multi-dimensional arrays. (3.2.1.8  Array Identifiers)
Also, there are dot operators for vectors in pov, so you might
want to store your point data in an array of vectors?
(3.2.1.4.3  Operators)

> or can MATRIX be used other than for transforms?)

In pov "matrix" is a keyword for matrix transforms.

Here's a simple example that reads a list of 10 vectors
(as floats) from a .csv file and makes a graph.

union{
#declare point = array[10];
#fopen handle "data.csv" read
#declare c = 0;
#while (c < 10)
   #read (handle, t1, t2, t3)
   #declare point[c] = <t1, t2, t3>;
   sphere{point[c],0.02}
   #declare c = c + 1;
#end
#fclose handle
#declare c = 1;
#while (c < 10)
   cylinder{point[c-1],point[c],0.02}
   #declare c = c + 1;
#end
pigment{rgb <1,0,0>}
}

//data.csv
0.0,0.0,0,
0.1,0.01,0,
0.2,0.1,0,
0.3,0.2,0,
0.4,0.25,0,
0.5,0.25,0,
0.6,0.2,0,
0.7,0.1,0,
0.8,0.01,0,
0.9,0.0,0


Post a reply to this message

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