POV-Ray : Newsgroups : povray.newusers : volume rendering from a text file containing positions in 3 dimensions Server Time
4 Jul 2024 14:16:38 EDT (-0400)
  volume rendering from a text file containing positions in 3 dimensions (Message 1 to 9 of 9)  
From: anki
Subject: volume rendering from a text file containing positions in 3 dimensions
Date: 12 Mar 2010 15:10:01
Message: <web.4b9a9f1d5498087ffdf151b0@news.povray.org>
dear users
i installed POV-Ray on a linux machine and it will be nice if somebody helps me
with the question below

i have a txt file containing spherical particle positions (x,y and z) and i want
to produce a 3 -dimensional image from this txt file

i just started using POV Ray today and i think we need to produce two files with
extension *.ini and *.pov from the text file of positions

thanks for the help
regards
anki


Post a reply to this message

From: Simon
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 12 Mar 2010 17:17:52
Message: <4b9abd90$1@news.povray.org>
Hi anki,

> i have a txt file containing spherical particle positions (x,y and z) and i want
> to produce a 3 -dimensional image from this txt file

POV is quite specific in what it will read in. You really need the data 
in CSV format:

x1,y1,z1,x2,y2,z2

To get a handle on the file, do this:
#fopen IDENTIFIER "filename" read

Then to read the next value(s) from a CSV, do this:
#read (IDENTIFIER, PosX, PosY, PosZ)

You now have the first 3 values in the variables PosX, PosY and PosZ

You'll also need to look at #while() to handle looping through the file

>
> i just started using POV Ray today and i think we need to produce two files with
> extension *.ini and *.pov from the text file of positions

The POV file defines the scene and the INI file is used to provide 
additional information (eg, How many frames to render in an animation, 
what file type to output, etc...)

My default INI file is:

==========================================================
Initial_Frame=0	;Start at frame 0
Final_Frame=100	;End at frame 100
Initial_Clock=0	;The variable "clock" will change from 0
Final_Clock=1	;to 1 ovr the course of the animation

;Frame Subset: This is done so you can render a couple of frames from an 
animation without altering the clock variable above
;Subset_Start_Frame = 100	;start at this frame
;Subset_End_Frame = 1439	;end at this frame

Input_File_Name=Scene.pov ;The POV file to render (usually in same 
directory)

Output_to_File=on	;Write out to file after rendering?
Output_File_Name= Frame	;The name of the file eg Frame0000.png

Cyclic_Animation=on ;Offset the end of the animation slightly so that a 
cyclic animation doesn't "jerk" as it loops through frame 0
==========================================================
Most of these have command line switches - See the help for more info


Hope that helps a bit


Post a reply to this message

From: Alain
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 13 Mar 2010 11:56:59
Message: <4b9bc3db$1@news.povray.org>

> dear users
> i installed POV-Ray on a linux machine and it will be nice if somebody helps me
> with the question below
>
> i have a txt file containing spherical particle positions (x,y and z) and i want
> to produce a 3 -dimensional image from this txt file
>
> i just started using POV Ray today and i think we need to produce two files with
> extension *.ini and *.pov from the text file of positions
>
> thanks for the help
> regards
> anki
>
>
>
In your text file, are the values separated by comas or by spaces?
In the first case, a simple #while loop is all you need to read those 
values.
If you don't know how many elements are in the file, you can use 
#while(!eof <file>).... #end to read untill you reatch the end of the 
text file. In that case, you read the first 3 values before you start 
the loop, and you read the next 3 as the last instruction of the loop, 
just before the #end.

In the second case, it's beter to do a search and replace to replace the 
spaces by comas.

The text file is not used to generate the *.ini nor the *.pov file. The 
*.pov file will use the *.txt file as a data source.

The *.pov file is the one actualy describing the scene: camera location 
and caracteristics, light(s) location(s) intensity and colours, what 
objects to place at each locations with what texture,... In the *.pov 
file, you will read your data and construct the scene from that.

The *.ini file is optional. You can render the *.pov file directly from 
the command line:
<path>pvengine.exe file.pov
You can add the image's dimentions the same way, just add +w1025 +h768 
to get a 1024 by 768 pixels image.

The *.ini file is mostly usefull when you need to enter several 
arguments and it becomes unweldy to always write them on the command 
line. It's also very usefull when doing animations as Simon proposed 
with his sample.
You can have a *test.ini to do the test renders, then a *.ini or 
*final.ini file to render the final image. Both versions refers to the 
same *.pov file.
The test version will have smaler resolution and lower, or no, aa, 
possibly lower quality setting, less animation frames,...
The final version will use full quality, good aa, larger resolution, all 
the animation's frames,...


Alain


Post a reply to this message

From: anki
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 17 Mar 2010 12:45:01
Message: <web.4ba10674d4b839cffdf151b0@news.povray.org>
Hi  Alain and Simon

Thanks a lot for your reply, atleast some things are clear now

actually my text file looks like below
1st column is sphere number
2nd column is x-position, 3rd- y position and 4th- z -position
there are 4000 particles in a box

1 487.726807 383.565125 99.485672
2 377.206238 393.352325 17.296064
3 452.328613 346.985321 33.054535
4 453.301697 334.173981 14.480576
5 724.187988 389.938171 55.237068
6 298.778717 388.706055 30.780521
7 685.588074 366.411072 31.322350
...............................
.........................
...........................
4000 56.78   456.67   234.56


i can make the text file , where columns are separated by commas like

x1,y1,z1
x2,y2,z2
x3,y3,z3
......
......

still i have a doubt about the format to use in *.pov file to read this text
file

is it like to put the commands as

"#fopen identifier 'pos.txt' read
while loop
end"    in a file named sphere.pov and use ./povray sphere.pov to produce
rendering image ?

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

thank you very much
regards
anki













Alain <aze### [at] qwertyorg> wrote:

> > dear users
> > i installed POV-Ray on a linux machine and it will be nice if somebody helps me
> > with the question below
> >
> > i have a txt file containing spherical particle positions (x,y and z) and i want
> > to produce a 3 -dimensional image from this txt file
> >
> > i just started using POV Ray today and i think we need to produce two files with
> > extension *.ini and *.pov from the text file of positions
> >
> > thanks for the help
> > regards
> > anki
> >
> >
> >
> In your text file, are the values separated by comas or by spaces?
> In the first case, a simple #while loop is all you need to read those
> values.
> If you don't know how many elements are in the file, you can use
> #while(!eof <file>).... #end to read untill you reatch the end of the
> text file. In that case, you read the first 3 values before you start
> the loop, and you read the next 3 as the last instruction of the loop,
> just before the #end.
>
> In the second case, it's beter to do a search and replace to replace the
> spaces by comas.
>
> The text file is not used to generate the *.ini nor the *.pov file. The
> *.pov file will use the *.txt file as a data source.
>
> The *.pov file is the one actualy describing the scene: camera location
> and caracteristics, light(s) location(s) intensity and colours, what
> objects to place at each locations with what texture,... In the *.pov
> file, you will read your data and construct the scene from that.
>
> The *.ini file is optional. You can render the *.pov file directly from
> the command line:
> <path>pvengine.exe file.pov
> You can add the image's dimentions the same way, just add +w1025 +h768
> to get a 1024 by 768 pixels image.
>
> The *.ini file is mostly usefull when you need to enter several
> arguments and it becomes unweldy to always write them on the command
> line. It's also very usefull when doing animations as Simon proposed
> with his sample.
> You can have a *test.ini to do the test renders, then a *.ini or
> *final.ini file to render the final image. Both versions refers to the
> same *.pov file.
> The test version will have smaler resolution and lower, or no, aa,
> possibly lower quality setting, less animation frames,...
> The final version will use full quality, good aa, larger resolution, all
> the animation's frames,...
>
>
> Alain


Post a reply to this message

From: Christian Froeschlin
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
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

From: Alain
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 17 Mar 2010 19:17:02
Message: <4ba162ee$1@news.povray.org>

> Hi  Alain and Simon
>
> Thanks a lot for your reply, atleast some things are clear now
>
> actually my text file looks like below
> 1st column is sphere number
> 2nd column is x-position, 3rd- y position and 4th- z -position
> there are 4000 particles in a box
>
> 1 487.726807 383.565125 99.485672
> 2 377.206238 393.352325 17.296064
> 3 452.328613 346.985321 33.054535
> 4 453.301697 334.173981 14.480576
> 5 724.187988 389.938171 55.237068
> 6 298.778717 388.706055 30.780521
> 7 685.588074 366.411072 31.322350
> ...............................
> .........................
> ...........................
> 4000 56.78   456.67   234.56
>
>
> i can make the text file , where columns are separated by commas like
>
> x1,y1,z1
> x2,y2,z2
> x3,y3,z3
> ......
> ......
>
> still i have a doubt about the format to use in *.pov file to read this text
> file
>
> is it like to put the commands as
>
> "#fopen identifier 'pos.txt' read
> while loop
> end"    in a file named sphere.pov and use ./povray sphere.pov to produce
> rendering image ?
>
> could you please suggest me a sample *.pov file which reads a text file
> containing the positions of particles like i have
>
> thank you very much
> regards
> anki
>

Put a coma after each values.

Sample file:

#declare Cluster = union{
  #fopen DATA_FILE "pos.txt" read
  #read(DATA_FILE, PosX, PosY, PosZ)
   #while (defined(DATA_FILE))
  	sphere{<PosX, PosY, PosZ>, Radius}
   #end
   #fclose DATA_FILE
   pigment{rgb 1}
   }

It opens your input file and read the first 3 values.
It then start a loop.
The loop place a single sphere, then it reads the next 3 values.

It will continue to loop until you reatch the end of your file. At that 
moment, DATA_FILE becomes undefined and the loop falls through.
The #fclose DATA_FILE is not realy needed as the file is automaticaly 
closed, and it's identifier suppressed, after you tried to read past 
it's end.
After the end of the loop, a texture is applied to the union and the 
union is closed.

I used a #declare. It allows you to use your cluster of spheres several 
times with no need to read your data a second time.

This construction allows you to read any file of any length with no need 
to know how many elements are contained in it.
You don't need any array.

You can use any object as your shape, you are not limited to use spheres.


Alain


Post a reply to this message

From: anki
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 22 Mar 2010 11:20:01
Message: <web.4ba78a8ad4b839c79d090110@news.povray.org>
Dear Alain and Christian

Thank you very much for your response and giving me suggestions to read the text
file.
I am able to produce the image, but still i have got some issues

I use camera location and look_at and light_source with these positions given
below.

Actually i used different positions for them to get a nice 3-dimensional image,
but i think i am not using optimal values

the set of particles positions i have, x-position ranges from 0.0 to 40.0;
y-position ranges from 0.0-20.0 and z-position ranges from 0-10.0

that means x-dimension is of 40 particle diameter length; y-dimension is of
20-particle diameter length and z-dimension is of 10-particle diameter length

particle diameter is 1.0

could you please suggest me the best way to put the light source and camera
position


background { color Cyan}
camera {
    location <0, 5, -3>
    look_at  <24, 9, 2>
}
light_source { <10, 5, -3> color White}



thanking you
anki








lain <aze### [at] qwertyorg> wrote:

> > Hi  Alain and Simon
> >
> > Thanks a lot for your reply, atleast some things are clear now
> >
> > actually my text file looks like below
> > 1st column is sphere number
> > 2nd column is x-position, 3rd- y position and 4th- z -position
> > there are 4000 particles in a box
> >
> > 1 487.726807 383.565125 99.485672
> > 2 377.206238 393.352325 17.296064
> > 3 452.328613 346.985321 33.054535
> > 4 453.301697 334.173981 14.480576
> > 5 724.187988 389.938171 55.237068
> > 6 298.778717 388.706055 30.780521
> > 7 685.588074 366.411072 31.322350
> > ...............................
> > .........................
> > ...........................
> > 4000 56.78   456.67   234.56
> >
> >
> > i can make the text file , where columns are separated by commas like
> >
> > x1,y1,z1
> > x2,y2,z2
> > x3,y3,z3
> > ......
> > ......
> >
> > still i have a doubt about the format to use in *.pov file to read this text
> > file
> >
> > is it like to put the commands as
> >
> > "#fopen identifier 'pos.txt' read
> > while loop
> > end"    in a file named sphere.pov and use ./povray sphere.pov to produce
> > rendering image ?
> >
> > could you please suggest me a sample *.pov file which reads a text file
> > containing the positions of particles like i have
> >
> > thank you very much
> > regards
> > anki
> >
>
> Put a coma after each values.
>
> Sample file:
>
> #declare Cluster = union{
>   #fopen DATA_FILE "pos.txt" read
>   #read(DATA_FILE, PosX, PosY, PosZ)
>    #while (defined(DATA_FILE))
>    sphere{<PosX, PosY, PosZ>, Radius}
>    #end
>    #fclose DATA_FILE
>    pigment{rgb 1}
>    }
>
> It opens your input file and read the first 3 values.
> It then start a loop.
> The loop place a single sphere, then it reads the next 3 values.
>
> It will continue to loop until you reatch the end of your file. At that
> moment, DATA_FILE becomes undefined and the loop falls through.
> The #fclose DATA_FILE is not realy needed as the file is automaticaly
> closed, and it's identifier suppressed, after you tried to read past
> it's end.
> After the end of the loop, a texture is applied to the union and the
> union is closed.
>
> I used a #declare. It allows you to use your cluster of spheres several
> times with no need to read your data a second time.
>
> This construction allows you to read any file of any length with no need
> to know how many elements are contained in it.
> You don't need any array.
>
> You can use any object as your shape, you are not limited to use spheres.
>
>
> Alain


Post a reply to this message

From: Christian Froeschlin
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 22 Mar 2010 19:16:45
Message: <4ba7fa5d$1@news.povray.org>
anki wrote:

> could you please suggest me the best way to put the light source and camera
> position

there is no general answer to this ... how should the image look
like? I'd probably start by translating the particles by <-20,-10,0>
and placing the camera at <0,0,-10> with look_at <0,0,0>. Then the
objects are centered and the initial setup is easy to understand.
Next, change the distance of the camera and play with the angle
keyword to get the desired zoom. The light should probably be
much further away from the origin, try an initial value of
<-100,80,-60> or so. Finally, move the camera to the side
or rotate the geometry to get the desired perspective.


Post a reply to this message

From: Alain
Subject: Re: volume rendering from a text file containing positions in 3 dimensions
Date: 22 Mar 2010 19:29:32
Message: <4ba7fd5c$1@news.povray.org>

> Dear Alain and Christian
>
> Thank you very much for your response and giving me suggestions to read the text
> file.
> I am able to produce the image, but still i have got some issues
>
> I use camera location and look_at and light_source with these positions given
> below.
>
> Actually i used different positions for them to get a nice 3-dimensional image,
> but i think i am not using optimal values
>
> the set of particles positions i have, x-position ranges from 0.0 to 40.0;
> y-position ranges from 0.0-20.0 and z-position ranges from 0-10.0
>
> that means x-dimension is of 40 particle diameter length; y-dimension is of
> 20-particle diameter length and z-dimension is of 10-particle diameter length
>
> particle diameter is 1.0
>
> could you please suggest me the best way to put the light source and camera
> position
>
>
> background { color Cyan}
> camera {
>      location<0, 5, -3>
>      look_at<24, 9, 2>
> }
> light_source {<10, 5, -3>  color White}
>
>
>
> thanking you
> anki
>
>
>
>
>
>
>
>
> lain<aze### [at] qwertyorg>  wrote:

>>> Hi  Alain and Simon
>>>
>>> Thanks a lot for your reply, atleast some things are clear now
>>>
>>> actually my text file looks like below
>>> 1st column is sphere number
>>> 2nd column is x-position, 3rd- y position and 4th- z -position
>>> there are 4000 particles in a box
>>>
>>> 1 487.726807 383.565125 99.485672
>>> 2 377.206238 393.352325 17.296064
>>> 3 452.328613 346.985321 33.054535
>>> 4 453.301697 334.173981 14.480576
>>> 5 724.187988 389.938171 55.237068
>>> 6 298.778717 388.706055 30.780521
>>> 7 685.588074 366.411072 31.322350
>>> ...............................
>>> .........................
>>> ...........................
>>> 4000 56.78   456.67   234.56
>>>
>>>
>>> i can make the text file , where columns are separated by commas like
>>>
>>> x1,y1,z1
>>> x2,y2,z2
>>> x3,y3,z3
>>> ......
>>> ......
>>>
>>> still i have a doubt about the format to use in *.pov file to read this text
>>> file
>>>
>>> is it like to put the commands as
>>>
>>> "#fopen identifier 'pos.txt' read
>>> while loop
>>> end"    in a file named sphere.pov and use ./povray sphere.pov to produce
>>> rendering image ?
>>>
>>> could you please suggest me a sample *.pov file which reads a text file
>>> containing the positions of particles like i have
>>>
>>> thank you very much
>>> regards
>>> anki
>>>
>>
>> Put a coma after each values.
>>
>> Sample file:
>>
>> #declare Cluster = union{
>>    #fopen DATA_FILE "pos.txt" read
>>    #read(DATA_FILE, PosX, PosY, PosZ)
>>     #while (defined(DATA_FILE))
>>     sphere{<PosX, PosY, PosZ>, Radius}
>>     #end
>>     #fclose DATA_FILE
>>     pigment{rgb 1}
>>     }
>>
>> It opens your input file and read the first 3 values.
>> It then start a loop.
>> The loop place a single sphere, then it reads the next 3 values.
>>
>> It will continue to loop until you reatch the end of your file. At that
>> moment, DATA_FILE becomes undefined and the loop falls through.
>> The #fclose DATA_FILE is not realy needed as the file is automaticaly
>> closed, and it's identifier suppressed, after you tried to read past
>> it's end.
>> After the end of the loop, a texture is applied to the union and the
>> union is closed.
>>
>> I used a #declare. It allows you to use your cluster of spheres several
>> times with no need to read your data a second time.
>>
>> This construction allows you to read any file of any length with no need
>> to know how many elements are contained in it.
>> You don't need any array.
>>
>> You can use any object as your shape, you are not limited to use spheres.
>>
>>
>> Alain
>
>
>
>

With no access to your data, it's dificult to juge, but I'll try using a 
set of 4000 randomly placed spheres.

You can try moving the camera around until you find a spot from where 
you get an interesting view.
Maybe moving the light to a somewhat larger distance from your spheres. 
I think that it may be to close, but it may need to be that close.
Some times, adding a second light can help.

Adding some highlight can add a lot but may not be interesting/advisable 
in your case. Try it to see.

You may try using smaler spheres, presently, there is a lot of overlaping.



Alain


Post a reply to this message

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