POV-Ray : Newsgroups : povray.newusers : volume rendering from a text file containing positions in 3 dimensions : Re: volume rendering from a text file containing positions in 3 dimensions Server Time
7 Jul 2024 08:33:23 EDT (-0400)
  Re: volume rendering from a text file containing positions in 3 dimensions  
From: Christian Froeschlin
Date: 17 Mar 2010 16:00:12
Message: <4ba134cc$1@news.povray.org>
anki wrote:

> could you please suggest me a sample *.pov file which reads a text file
> containing the positions of particles like i have

Here is some sample code which should get you started.
Note that the file format needs to have a comma at the end
of the line as well!

// You mentioned you know the number of points, otherwise do two passes.
#declare NUM = 4000;

// Open data file
#fopen DATA_FILE "pos.txt" read

// Read data
#declare POS_X    = array[NUM]; // Create and initialize arrays
#declare POS_Y    = array[NUM];
#declare POS_Z    = array[NUM];
#declare POS_X[0] = 0.0;
#declare POS_Y[0] = 0.0;
#declare POS_Z[0] = 0.0;
#declare INDEX = 0;
#while (defined(DATA_FILE) & INDEX < NUM)
   #read(DATA_FILE,POS_X[INDEX],POS_Y[INDEX],POS_Z[INDEX])
   #declare INDEX = INDEX+1;
#end
#declare NUM = INDEX; // Fewer than expected is ok

#fclose DATA_FILE

// Use data
union
{
   #declare INDEX = 0;
   #while (INDEX < NUM)
     sphere {<POS_X[INDEX],POS_Y[INDEX],POS_Z[INDEX]>, 1}
     #declare INDEX = INDEX+1;
   #end

   pigment {color rgb 1}
}


Post a reply to this message

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