POV-Ray : Newsgroups : povray.newusers : Possible to use coordinates from an external text file? Server Time
21 Dec 2024 12:54:49 EST (-0500)
  Possible to use coordinates from an external text file? (Message 1 to 6 of 6)  
From: TomB
Subject: Possible to use coordinates from an external text file?
Date: 19 Oct 2015 10:40:01
Message: <web.5624fffcd480363d81763ba0@news.povray.org>
Hi,

I am brand new to POV-Ray, and want to use it to visualize some scientific data.
I would like to know if it is possible to read in coordinates from an external
text file. For example, if I want to create a number of spheres at coordinates
[x,y,z], but these coordinates are stored in another file - I don't want to copy
them all into the POV-Ray script. Or if anyone could point me to some resource
online for this kind of thing?

Any advice would be appeciated,

Thanks!

Tom


Post a reply to this message

From: clipka
Subject: Re: Possible to use coordinates from an external text file?
Date: 19 Oct 2015 11:53:30
Message: <562511fa$1@news.povray.org>
Am 19.10.2015 um 16:36 schrieb TomB:
> Hi,
> 
> I am brand new to POV-Ray, and want to use it to visualize some scientific data.
> I would like to know if it is possible to read in coordinates from an external
> text file. For example, if I want to create a number of spheres at coordinates
> [x,y,z], but these coordinates are stored in another file - I don't want to copy
> them all into the POV-Ray script. Or if anyone could point me to some resource
> online for this kind of thing?

You may want to have a look at POV-Ray's "#read" directive.

Alternatively, if you have full control over the format of the external
text file, you can use the "#include" directive in some creative way.


Post a reply to this message

From: Kenneth
Subject: Re: Possible to use coordinates from an external text file?
Date: 20 Oct 2015 04:20:00
Message: <web.5625f8902a4ca8dd33c457550@news.povray.org>
"TomB" <nomail@nomail> wrote:

>
> I would like to know if it is possible to read in coordinates from an external
> text file. For example, if I want to create a number of spheres at coordinates
> [x,y,z], but these coordinates are stored in another file...

The #read directive in POV-Ray is quite useful and powerful for this kind of
thing. A possible stumbling-block is that your text file may not be in a form
that's immediately readable, as the #read directive requires a certain kind of
formatting. But that's fixable in any word-processing app (I use Edit Pad Lite
for this, to do any global search-and-replace of things that #read doesn't
handle well, liked tabbed white space for example.)

I would suggest trying to #read in your text file as-is, as a first try. It will
either work or it won't ;-) If it doesn't, then you'll need to 'massage' it
until it does. (That's a good learning exercise in itself!)


Post a reply to this message

From: TomB
Subject: Re: Possible to use coordinates from an external text file?
Date: 22 Oct 2015 10:25:00
Message: <web.5628f1462a4ca8dd81763ba0@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> "TomB" <nomail@nomail> wrote:
>
> >
> > I would like to know if it is possible to read in coordinates from an external
> > text file. For example, if I want to create a number of spheres at coordinates
> > [x,y,z], but these coordinates are stored in another file...
>
> The #read directive in POV-Ray is quite useful and powerful for this kind of
> thing. A possible stumbling-block is that your text file may not be in a form
> that's immediately readable, as the #read directive requires a certain kind of
> formatting. But that's fixable in any word-processing app (I use Edit Pad Lite
> for this, to do any global search-and-replace of things that #read doesn't
> handle well, liked tabbed white space for example.)
>
> I would suggest trying to #read in your text file as-is, as a first try. It will
> either work or it won't ;-) If it doesn't, then you'll need to 'massage' it
> until it does. (That's a good learning exercise in itself!)


Thank you both for your helpful replies. This function is exactly what I was
looking for.


Post a reply to this message

From: TomB
Subject: Re: Possible to use coordinates from an external text file?
Date: 22 Oct 2015 10:50:04
Message: <web.5628f7482a4ca8dd81763ba0@news.povray.org>
Okay, so I have what is probably another very simple question.

I have created a very simple text file, which contains the line:

<0,5,0>

and then us the following code to draw a sphere at the position given by teh
vector in the file:

     #include "colors.inc"
     light_source { <100,1000,-1000>, White}
     camera { location <0,0,-20> look_at <0,0,0>}

     #fopen FileHandle "coords.txt" read
     #read (FileHandle,coordVector)
     #fclose FileHandle

     sphere{<coordVector.x,coordVector.y,coordVector.z>,1 pigment{color Red}}

This all works nicely. However, is there a way to read in an arbitrary number of
lines from the text file, like:

<0,5,0>
<0,0,0>
....
....
<xn,yn,zn>


and draw the corresponding spheres, without using any loops... i.e. is it
possible for POV-Ray to import and work with a single matrix, where the first
column is all the x coordinates, etc.

Many thanks,

Tom


Post a reply to this message

From: Thomas de Groot
Subject: Re: Possible to use coordinates from an external text file?
Date: 23 Oct 2015 02:58:02
Message: <5629da7a@news.povray.org>
On 22-10-2015 16:48, TomB wrote:
> Okay, so I have what is probably another very simple question.
>
> I have created a very simple text file, which contains the line:
>
> <0,5,0>
>
> and then us the following code to draw a sphere at the position given by teh
> vector in the file:
>
>       #include "colors.inc"
>       light_source { <100,1000,-1000>, White}
>       camera { location <0,0,-20> look_at <0,0,0>}
>
>       #fopen FileHandle "coords.txt" read
>       #read (FileHandle,coordVector)
>       #fclose FileHandle
>
>       sphere{<coordVector.x,coordVector.y,coordVector.z>,1 pigment{color Red}}
>
> This all works nicely. However, is there a way to read in an arbitrary number of
> lines from the text file, like:
>
> <0,5,0>
> <0,0,0>
> ....
> ....
> <xn,yn,zn>
>
>
> and draw the corresponding spheres, without using any loops... i.e. is it
> possible for POV-Ray to import and work with a single matrix, where the first
> column is all the x coordinates, etc.
>
> Many thanks,
>
> Tom
>
>
>
>

Yes, that is very simple to do with a defined() function. In your case 
that would be:

#fopen FileHandle "coords.txt" read
union {
#while (defined (FileHandle))
   #read (FileHandle,coordVector)
   sphere {coordVector, Radius
      texture {MyTexture}
   }
#end
} //close union
#fclose FileHandle

Note that your text file needs separators between entries, except the 
last one:

  <0,5,0>,
  <0,0,0>,
  ....,
  ....,
  <xn,yn,zn>

-- 
Thomas


Post a reply to this message

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