|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
This should be easy, but I'm having some trouble.
I would like to read a series of vectors <x,y,z> from a text file and plot the
points as spheres. To test things out, I made a text file with 2 vectors
separated by commas.
I get this error message. Can anyone tell me what I am doing wrong?
//-------------------------------------------
#fopen MyFile "myData.txt" read
# local i = 1;
#while (i<2)
#read (MyFile,Vector[i]
Parse Error: Expected 'undeclared identifier', empty array found instead
//---------------------------------------------
Here is the POV-Ray code I used:
#declare maxArray = 2;
#declare Vector = array[maxArray];
#fopen MyFile "myData.txt" read
# local i = 1;
#while (i<2)
#read (MyFile,Vector[i])
#local i = i + 1;
#end
#declare Graphic = union {
sphere {
Vector[i], 1 texture {
pigment { color rgb <1,0,0> }
finish { Substance }
}
}
sphere {
Vector[i], 1 texture {
pigment { color rgb <1,1,0 > }
finish { Substance }
}
}
} // end of Graphic
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 01/05/2012 08:44 AM, Scott wrote:
> This should be easy, but I'm having some trouble.
>
> I would like to read a series of vectors<x,y,z> from a text file and plot the
> points as spheres. To test things out, I made a text file with 2 vectors
> separated by commas.
>
> I get this error message. Can anyone tell me what I am doing wrong?
>
> //-------------------------------------------
> #fopen MyFile "myData.txt" read
> # local i = 1;
> #while (i<2)
> #read (MyFile,Vector[i]
> Parse Error: Expected 'undeclared identifier', empty array found instead
> //---------------------------------------------
have a look at the following if you've not done that already:
http://wiki.povray.org/content/Documentation:Reference_Section_2.3#Array_Identifiers
should be #local i = 0; ????
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Jim Holsenback <nom### [at] nomailcom> wrote:
> On 01/05/2012 08:44 AM, Scott wrote:
> > This should be easy, but I'm having some trouble.
> >
> > I would like to read a series of vectors<x,y,z> from a text file and plot the
> > points as spheres. To test things out, I made a text file with 2 vectors
> > separated by commas.
> >
> > I get this error message. Can anyone tell me what I am doing wrong?
> >
> > //-------------------------------------------
> > #fopen MyFile "myData.txt" read
> > # local i = 1;
> > #while (i<2)
> > #read (MyFile,Vector[i]
> > Parse Error: Expected 'undeclared identifier', empty array found instead
> > //---------------------------------------------
>
> have a look at the following if you've not done that already:
> http://wiki.povray.org/content/Documentation:Reference_Section_2.3#Array_Identifiers
>
> should be #local i = 0; ????
Thanks. However, I had previously checked out that section of the POV
reference. I did initially have the #local i = 0, but that did not help.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
You may also consider using:
#wile (defined(filename))
...
#end
Thomas
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
The #read section in the docs says that a vector identifier used in this way
should be predeclared. You've declared the array, but not initialised the
element you're trying to read into. Try:
#fopen MyFile "myData.txt" read
#local i = 1;
#while (i<2)
#local Vector[i] = <0,0,0>;
#read (MyFile,Vector[i])
#local i = i + 1;
#end
Also note that arrays are zero-based in index, and your code will only attempt
to read 1 vector from the file. You should set i = 0 instead, unless I have
misread your intentions!
Bill
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
It seems to me that arrays are unduly complicated in use here.
Personally, I would prefer the following:
#fopen MyFile "myData.txt" read
#while (defined(MyFile))
#read (MyFile,Vector)
#end
see: 3.2.2.3.3 The #read Directive
Thomas
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Thank you both Thomas and Bill for your comments.
I came up with 2 versions that work. One defines an array for the points, and
the other seems to work just as well without it.
Here are the 2 versions.
1) No array
#fopen MyFile "Set_of_PointsXYZ.txt" read
#local i = 0;
#while (defined(MyFile))
#read (MyFile,Vector)
sphere { Vector, 0.1
texture {
pigment{ rgb <1,0,0>}
finish { Substance }}}
#local i = i + 1;
#end
2) Using an array
#declare Vector = array[100000];
#fopen MyFile "Set_of_PointsXYZ.txt" read
#local i = 0;
#while (defined(MyFile))
#local Vector [i] = <0,0,0>;
#read (MyFile,Vector[i])
sphere { Vector[i], 0.1
texture {
pigment{ rgb <1,0,0>}
finish { Substance }}}
Again, thanks so much for your assistance.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
It looks like for your no-array option, you don't need "i" either.
Charles
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> Thank you both Thomas and Bill for your comments.
>
> I came up with 2 versions that work. One defines an array for the points, and
> the other seems to work just as well without it.
>
> Here are the 2 versions.
>
> 1) No array
>
> #fopen MyFile "Set_of_PointsXYZ.txt" read
>
> #local i = 0;
> #while (defined(MyFile))
> #read (MyFile,Vector)
> sphere { Vector, 0.1
> texture {
> pigment{ rgb<1,0,0>}
> finish { Substance }}}
> #local i = i + 1;
> #end
>
> 2) Using an array
>
> #declare Vector = array[100000];
> #fopen MyFile "Set_of_PointsXYZ.txt" read
> #local i = 0;
> #while (defined(MyFile))
> #local Vector [i] =<0,0,0>;
> #read (MyFile,Vector[i])
> sphere { Vector[i], 0.1
> texture {
> pigment{ rgb<1,0,0>}
> finish { Substance }}}
>
> Again, thanks so much for your assistance.
>
>
Unless you plan having each spheres painted with different textures, you
should use an union and aply the texture to the union as a whole.
Using your non-array solution, it gives this:
#fopen MyFile "Set_of_PointsXYZ.txt" read
#declare DotedSphere=
union{
#while (defined(MyFile))
#read (MyFile,Vector)
sphere { Vector, 0.1}
#end
texture{pigment{rgb<1,0,0>}finish{Substance}}
}
Faster to parse as it uses less statements and takes less place in
memory. If you have 100000 points or more, the memory requirement can
become an isue.
It may also be faster to render.
You can #declare the union and use it in more than one place.
Alain
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
In the no array version, there is no need for i. Defined takes care of
it all. What Alain says is important. It is a technique that I use for
all of my scenes with a write/read code. And you can make the union
and/or the while loop as complex as you want of course.
Thomas
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |