POV-Ray : Newsgroups : povray.windows : How to generate sphere and cylinder with csv file Server Time
31 Oct 2024 00:36:01 EDT (-0400)
  How to generate sphere and cylinder with csv file (Message 1 to 10 of 31)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Jeff
Subject: How to generate sphere and cylinder with csv file
Date: 27 Mar 2017 08:20:01
Message: <web.58d90246d665dbbed33c50560@news.povray.org>
so, i have csv files that i would like to use to do the visualization.its
something like below:

mode country/city ID         lon         lat
bus CN/Beijing bus2382659521 116.4093833 39.9067192
bus CN/Beijing bus1636776952 116.3039935 39.8888451
rail CN/Beijing rail269996666 116.4209908 39.9016416
rail CN/Beijing rail1419861955 116.3465335 39.9430318
subway CN/Beijing subway339089932 116.3572162 39.8980033
subway CN/Beijing subway339086386 116.3041387 39.9061679
tram CN/Beijing tram1408143389 116.3920808 39.8904203
tram CN/Beijing tram1408143387 116.3917507 39.896844


so, i want to generate some spheres to represent the information in the csv file
above,
how do i generate different color of spheres for different mode, and use the
"lon" column as the Y position of the sphere, and "lat" column as the Z
position?



and the other csv file is something like this:

mode Source           Target            length
bus bus332263578   bus2052937452            59.34930975
bus bus268389450   bus268389107            101.9938894
rail rail539260172   rail1182599524           571.7497256
rail rail1182599524   rail273113548            568.8268748
subway subway245154338   subway245143068          81.85897267
subway subway336935693   subway3369356929         99.88085188

then i use these information to generate cylinder and connect the it to sphere
accordingly by using the "Source" column and "Target" column and the "length"
column as the length of the cylinders.

can someone help me please?


Post a reply to this message

From: Bald Eagle
Subject: Re: How to generate sphere and cylinder with csv file
Date: 27 Mar 2017 10:15:00
Message: <web.58d91d7eae95604bc437ac910@news.povray.org>
"Jeff" <jef### [at] gmailcom> wrote:

> so, i want to generate some spheres to represent the information in the csv file
> above,
> how do i generate different color of spheres for different mode,

So, real quick,

#include "colors.inc"
#if (variable = "bus")
  #declare Color = pigment {Red};
#else if (variable2 = "rail")

#else
#end

Write your data to a text file, use the #open, #read directives to read the
values in.

#declare a Y variable as that value.
same for the Z variable  (notice both are Uppercase)

searching for:  #read #write data from file
pulls up the following, with lots more

http://news.povray.org/povray.general/thread/%3Cweb.4d05993a67d8c71bd6b9b2630@news.povray.org%3E/?ttop=357624&toff=50

http://news.povray.org/povray.general/thread/%3Cweb.43886ab1919621bdcce6fd2b0@news.povray.org%3E/?ttop=330491&toff=1350




> then i use these information to generate cylinder and connect the it to sphere
> accordingly by using the "Source" column and "Target" column and the "length"
> column as the length of the cylinders.

Don't worry about the length, just use the coordinates of the 2 spheres as the
endpoint coordinates of the cylinder.

You're probably going to have to convert your values from long/lat to some
meaningful x,y,z coordinates (polar to Cartesian)


Post a reply to this message

From: Mike Horvath
Subject: Re: How to generate sphere and cylinder with csv file
Date: 27 Mar 2017 23:47:43
Message: <58d9dcdf$1@news.povray.org>
I usually do conversions like this in Excel or using some external 
script. You can mix the numbers with short strings of text to generate 
valid POV-Ray code.


Mike


Post a reply to this message

From: Jeff
Subject: Re: How to generate sphere and cylinder with csv file
Date: 28 Mar 2017 07:25:00
Message: <web.58da47d9ae95604b4de507a60@news.povray.org>
From: "Jeff" <jef### [at] gmailcom>
Newsgroups: povray.windows
Subject: Re: How to generate sphere and cylinder with csv file

"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, real quick,
>
> #include "colors.inc"
> #if (variable = "bus")
>   #declare Color = pigment {Red};
> #else if (variable2 = "rail")
>
> #else
> #end
>
> Write your data to a text file, use the #open, #read directives to read the
> values in.
>
> #declare a Y variable as that value.
> same for the Z variable  (notice both are Uppercase)
>
> searching for:  #read #write data from file
> pulls up the following, with lots more
>
>http://news.povray.org/povray.general/thread/%3Cweb.4d05993a67d8c71bd6b9b2630@news.povray.org%3E/?ttop=357624&toff=50
>
>
http://news.povray.org/povray.general/thread/%3Cweb.43886ab1919621bdcce6fd2b0@news.povray.org%3E/?ttop=330491&toff=13
50

>
> Don't worry about the length, just use the coordinates of the 2 spheres as the
> endpoint coordinates of the cylinder.
>
> You're probably going to have to convert your values from long/lat to some
> meaningful x,y,z coordinates (polar to Cartesian)

hi, if i open the .csv file , and save it as .txt file, will that do the
conversion? and i have like 1000+ sphere that i need to generate from the data,
is there any efficient way to do it, instead of write down the sphere position?
so, is this the way to do it? hey, i want to talk more detail about, and i need
your help. here is my email: jef### [at] gmailcom. thanks before :)


#include "colors.inc"
#declare myImage = image{ png "C:\\Users\\Jeff\\Desktop\\beijing.png" }

#fopen nodesfile "nodes.txt" read
#fopen linksfile "links.txt" read
  #while (defined(nodesfile))
    #read (nodesfile,Var1,Var2,Var3,Var4)


#if (Var1 = "bus")
    #declare Color = pigment {Red};
#else if (Var2 = "subway")
    #declare Color = pigment {Green};
#else if (Var3 = "rail")
    #declare Color = pigment {Blue};
#else (Var4 = "tram")
    #declare Color = pigment {Yellow};
#end

camera
{ location <0,0,-10>
  look_at 0
  rotate <0,clock*360,0>
}

light_source    {
                <10,10,-10>
                color White
                }


Post a reply to this message

From: Bald Eagle
Subject: Re: How to generate sphere and cylinder with csv file
Date: 28 Mar 2017 08:00:00
Message: <web.58da4fecae95604bc437ac910@news.povray.org>
"Jeff" <jef### [at] gmailcom> wrote:

> hi, if i open the .csv file , and save it as .txt file, will that do the
> conversion?

The .csv file is essentially a text file in exactly the format that POV-Ray
needs it to be in.  "Comma Separated Values" = CSV

> and i have like 1000+ sphere that i need to generate from the data,

Not a problem - I've made scenes with millions.

> is there any efficient way to do it, instead of write down the sphere position?

Yes, that's why you're automating the process by reading in the values from an
existing file.
I'd start with a small fragment of the file - say 10-50 entries or so, and
output all of the variables you read in and calculate to the #ebug stream so
that you're sure about what you're working with, and passing on to POV-Ray.

I generally define a Verbose variable, then use
#if (Verbose)
     #debug "Debugging on \n"
     etc
#end
so that I'm not forever commenting and uncommenting debugging tools.

> #include "colors.inc"
> #declare myImage = image{ png "C:\\Users\\Jeff\\Desktop\\beijing.png" }

try:
#declare myImage = pigment {image_map {png "C:/Users/Jeff/Desktop/beijing.png"
}}
#declare Resolution = max_extent (myImage);
#declare ImageHeight = Resolution.y;
#declare ImageWidth = Resolution.x;

Then make a flat box:  box {0, 1, translate -0.5 pigment {myImage} scale
<Resolution.x, Resolution.y, 1>}


> #fopen nodesfile "nodes.txt" read
> #fopen linksfile "links.txt" read
>   #while (defined(nodesfile))
>     #read (nodesfile,Var1,Var2,Var3,Var4)
>
>
> #if (Var1 = "bus")
>     #declare Color = pigment {Red};
> #else if (Var2 = "subway")
>     #declare Color = pigment {Green};
> #else if (Var3 = "rail")
>     #declare Color = pigment {Blue};
> #else (Var4 = "tram")
>     #declare Color = pigment {Yellow};
> #end
>
> camera
> { location <0,0,-10>
>   look_at 0
>   rotate <0,clock*360,0>
> }

I'm not sure why you're using the Clock variable in your camera definition,
unless you plan on animating this later.
Probably gonna have to move that camera WAY back in the -z direction.
I'd also probably use an orthographic camera, and ambient_light to get aa pretty
flat, evenly lit scene, at least at the beginning.

> light_source    {
>                 <10,10,-10>
>                 color White
>                 }


Post a reply to this message

From: clipka
Subject: Re: How to generate sphere and cylinder with csv file
Date: 28 Mar 2017 09:40:53
Message: <58da67e5$1@news.povray.org>
Am 28.03.2017 um 13:58 schrieb Bald Eagle:
> "Jeff" <jef### [at] gmailcom> wrote:
> 
>> hi, if i open the .csv file , and save it as .txt file, will that do the
>> conversion?
> 
> The .csv file is essentially a text file in exactly the format that POV-Ray
> needs it to be in.  "Comma Separated Values" = CSV

Accordin to the OP it isn't really CSV, but rather tab-separated (or
blank-separated?) values.

These are /not/ ideally suited for the use with `#read`.


Post a reply to this message

From: Bald Eagle
Subject: Re: How to generate sphere and cylinder with csv file
Date: 28 Mar 2017 10:15:01
Message: <web.58da6f56ae95604bc437ac910@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:

> Accordin to the OP it isn't really CSV, but rather tab-separated (or
> blank-separated?) values.
>
> These are /not/ ideally suited for the use with `#read`.

Right on.
It looks like space or tab-delimited.
Perhaps the OP could link to the source.

Opening in Excel or OpenOffice and saving as true CSV ought to do it.

He's also going to need to fix that ID string with something like (untested):

#declare ID = substr(S3,strlen(S1),strlen(S3)-strlen(S1))

where S1 is the mode, and S3 is the ID.

(BTW, I didn't see a dedicated entry for "strlen()" in the F1 documentation
section on String Functions. Perhaps I overlooked it...)


Post a reply to this message

From: Jeff
Subject: Re: How to generate sphere and cylinder with csv file
Date: 29 Mar 2017 10:50:01
Message: <web.58dbc93eae95604b4de507a60@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> clipka <ano### [at] anonymousorg> wrote:
> > Accordin to the OP it isn't really CSV, but rather tab-separated (or
> > blank-separated?) values.
> >
> > These are /not/ ideally suited for the use with `#read`.
>
> Right on.
> It looks like space or tab-delimited.
> Perhaps the OP could link to the source.
>
> Opening in Excel or OpenOffice and saving as true CSV ought to do it.
-- so, i did try to run the code , and it shows me the list of information from
the nodes.csv file. so, its probably means it could work with it.


> He's also going to need to fix that ID string with something like (untested):
>
> #declare ID = substr(S3,strlen(S1),strlen(S3)-strlen(S1))
>
> where S1 is the mode, and S3 is the ID.
>
> (BTW, I didn't see a dedicated entry for "strlen()" in the F1 documentation
> section on String Functions. Perhaps I overlooked it...)
-- they are dedicated , but i just put some of it, because they are not in a
organized order. so, i just pick some samples from it.


#include "colors.inc"
#fopen nodesfile "C:\\Users\\Jeff\\Desktop\\nodes.csv" read
#fopen linksfile "C:\\Users\\Jeff\\Desktop\\links.csv" read
  #while (defined(nodesfile))
    #read (nodesfile,Var1,Var2,Var3,Var4)
#declare myImage = pigment {image_map {png "C:/Users/Jeff/Desktop/beijing.png"
}}
#declare Resolution = max_extent (myImage);
#declare ImageHeight = Resolution.y;
#declare ImageWidth = Resolution.x;
box {0, 1, translate -0.5 pigment {myImage} scale
<Resolution.x, Resolution.y, 1>}



#if (Verbose)
     #debug "Debugging on \n"
     etc
#end
#if (Var1 = "bus")
    #declare Color = pigment {Red};
#else if (Var2 = "subway")
    #declare Color = pigment {Green};
#else if (Var3 = "rail")
    #declare Color = pigment {Blue};
#else (Var4 = "tram")
    #declare Color = pigment {Yellow};
#end

camera {
   orthographic
   location <-1000,0,0>
   look_at 0
   rotate <0,clock*360,0>
   }

light_source    {
                <10,10,-1000>
                color White
                }

jeff.federick93@(gmail.com)is my email.


Post a reply to this message

From: clipka
Subject: Re: How to generate sphere and cylinder with csv file
Date: 29 Mar 2017 12:43:45
Message: <58dbe441@news.povray.org>
Am 29.03.2017 um 16:48 schrieb Jeff:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
>> clipka <ano### [at] anonymousorg> wrote:
>>> Accordin to the OP it isn't really CSV, but rather tab-separated (or
>>> blank-separated?) values.
>>>
>>> These are /not/ ideally suited for the use with `#read`.
>>
>> Right on.
>> It looks like space or tab-delimited.
>> Perhaps the OP could link to the source.
>>
>> Opening in Excel or OpenOffice and saving as true CSV ought to do it.
> -- so, i did try to run the code , and it shows me the list of information from
> the nodes.csv file. so, its probably means it could work with it.

IIRC, if your file format does not contain commas, the following may be
misinterpreted:

    47 11
    42 -12

While the first line would be interpreted as the individual numbers 47
and 11, the second line might be misinterpreted as the single number 30
(the result of the expression `42-12`).


Post a reply to this message

From: Bald Eagle
Subject: Re: How to generate sphere and cylinder with csv file
Date: 29 Mar 2017 15:20:00
Message: <web.58dc085aae95604bc437ac910@news.povray.org>
Here ya go.

Pay attention to the data format (see comments)

Needs scaling to fit (a) on the screen better and (b) on top of your image to
match locations

Better code would have methods built in to catch and reject erroneous data, etc.

But here are the basics.

=========================================================================

// Persistence of Vision Ray Tracer version 3.7
// Scene Description Language (SDL)
//      File: Latitude / Longitude Mapping
//      Version: 1.0
//      Last updated: 29-Mar-2017
//      Description: Read Latitude and Longitude from file and connect points on
map
//
// Author:   Bill Walker "Bald Eagle", 2017
// email:    see posts in news.povray.org
//
//------------------------------------------------------------------------

#version 3.7;

global_settings {
 assumed_gamma 1.0
 #default {texture {pigment {rgb <1, 1, 1>} finish {ambient 1}}}
 ambient_light rgb <1, 1, 1> // <======== flat, even illumination
}

#include "colors.inc"

camera {
 location <0, 0, -1>
 right    x*image_width/image_height
 look_at <0, 0, 0>
}

light_source{ <50, 50, -100>  color rgb <1, 1, 1>}

// #declare EarthRadius = 6367; //radius in km
#declare EarthRadius = 6367*0.621371; //radius in mi

#macro S2C (Spherical)
 // input - 2d vector: <Latitude, Longitude>
 #local Lat = radians (Spherical.x);
 #local Lon = radians (Spherical.y);
 #local X = EarthRadius * cos(Lat) * cos(Lon);
 #local Y = EarthRadius * cos(Lat) * sin(Lon);
 #local Z = EarthRadius * sin(Lat);
 #local Cartesian = <X, Y, Z>;
 Cartesian;
#end // end macro S2C


#macro C2S (Cartesian)

 #local R = sqrt(pow(Cartesian.x, 2) * pow(Cartesian.y, 2) * pow(Cartesian.z,
2));
 #local Lat = degrees (asin (Cartesian.z / R));
 #local Lon = degrees (atan2 (Cartesian.y, Cartesian.x));
 #local LatLon = <Lat, Lon>;
 LatLon;
#end // end macro C2S

//  data format: "bus", "CN/Beijing", "bus2382659521", 116.4093833, 39.9067192,
//    etc.
#declare Type = "";
#declare Location = "";
#declare ID = "";
#declare Latitude = 0;
#declare Longitude = 0;

// count locations for sizing array
#declare Locations = 0;
#fopen DataFile "LatLongData.txt" read
#while (defined (DataFile))
 #read (DataFile, Type, Location, ID, Latitude, Longitude)
 #declare Locations = Locations + 1;
#end
#fclose DataFile

#declare _Type = array[Locations];
#declare _Location = array[Locations];
#declare _ID = array[Locations];
#declare _Latitude = array[Locations];
#declare _Longitude = array[Locations];
#declare _XYZ = array[Locations];

// input data into array
#declare Datapoint = 0;
#fopen DataFile "LatLongData.txt" read
#while (defined (DataFile))
 #read (DataFile, Type, Location, ID, Latitude, Longitude)

 #declare _Type [Datapoint] = Type;
 #declare _Location [Datapoint] = Location;
 #declare _ID [Datapoint] = ID;
 #declare _Latitude [Datapoint] = Latitude;
 #declare _Longitude [Datapoint] = Longitude;
 #declare _XYZ [Datapoint] = S2C (<_Latitude[Datapoint],
_Longitude[Datapoint]>);
 #declare Datapoint = Datapoint + 1;
#end
#fclose DataFile

#declare Marker = 0.25;
#declare Line = 0.05;
#declare Linecolor = pigment {Magenta};

#for (Point, 0, Locations-1)

 #if (Type = "bus")
  #declare Color = pigment {Red};
 #elseif (Type = "subway")
  #declare Color = pigment {Green};
 #elseif (Type = "rail")
  #declare Color = pigment {Blue};
 #elseif (Type = "tram")
  #declare Color = pigment {Yellow};
 #else
  #debug "Unidentified Location Type.  \n"
  #declare Color = pigment {White};
 #end

 #declare S = 1; //<0.1, 0.1, 1/4000>;
 #declare T = <1350, 1130, -3500>;

 sphere {0, Marker pigment {Color} translate _XYZ[Point]*S translate T}

 #if (Point > 0)
  cylinder {LastPoint*S, _XYZ[Point]*S, Line pigment {Linecolor} translate T}
 #end // end if

 #debug concat( "Vector = ", vstr(3, _XYZ[Point]*S, ", ", 3, 0), " \n")

 #declare LastPoint = _XYZ[Point];

#end // end for Point


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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