Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: build array of geometry data

by MZSanford (Curate)
on Feb 10, 2003 at 14:16 UTC ( #234121=note: print w/ replies, xml ) Need Help??


in reply to build array of geometry data

I don't know renderman, so i am not sure how complex this is going to grow to, but i think the following will do something similar to what you are asking about : lightly-tested code ahead

#!/usr/bin/perl my $string; { $/ = undef; $string = <DATA>; } while ($string =~ m!\[\s*([^]]+)\]!g) { my @nums = split(/\s+/,$1); print "Array : ",join(',',@nums),"\n"; } __DATA__ [1 1 1 1 1 1 ][4 4 4 4 4 4] [ 123 123 123 123 123 123 123 123 123 ] "P" [ -1 1 1 1 1 -1 1 1 1 ]

If renderman has a very complex file format, you may want to write a more robust parser.


from the frivolous to the serious


Comment on Re: build array of geometry data
Download Code
Re: Re: build array of geometry data
by Frippe (Acolyte) on Feb 10, 2003 at 15:45 UTC
    Thanks for your fast reply !!! I use the open ( INPUT, .....) to read in the file and I want to seprate the 4 array's so something like this my @nloops = ...; my @lverts = ...; my @vertid = ...; my @paramslist = ...; so your code was nice to print this info but I like to asign it to 4 array ex. my @nloops = [ ... ]; my @lverts = [ ... ]; my @vertid = [ ... ]; my @params = [ ... ]; next I could count the array length this I know how to next I could build a for loop to assign 1 array and first value to new + data format ... ex. change the data 0.5 0.5 0.5 add 1 -------- first array to output 0.5 0.5 0.5 1 Print some info here !!! 4 < 1 2 3 4 Print end info !!! so in another words the 4 arrays need to be seprate. ex. print @nloops; OUT 1,1,1,1,1 print @lverts; OUT 4,4,4,4,4 ...

      I am unsure what you mean about changing the data. While i am not quite clear on that, i do understand you want to save each array of numbers seperatly. To accomplish this, i used an Array of Arrays. The code is listed below (it is untested) :

      #!/usr/bin/perl my $string; { $/ = undef; $string = <DATA>; } my @collection; while ($string =~ m!\[\s*([^]]+)\]!g) { my @nums = split(/\s+/,$1); print "Array : ",join(',',@nums),"\n"; push(@collection,\@nums); } ## Now, i have an array or arrays, like : # # @collection = ( # [1,1,1,...], # [4,4,4,...], # [123,123,123,123,...], # [-1,1,1,1,1,...], # ) print "nloops : ",join(',',@{$collection[0]}),"\n"; print "lverts : ",join(',',@{$collection[1]}),"\n"; print "vertid : ",join(',',@{$collection[2]}),"\n"; print "params : ",join(',',@{$collection[3]}),"\n"; __DATA__ [1 1 1 1 1 1 ][4 4 4 4 4 4] [ 123 123 123 123 123 123 123 123 123 ] "P" [ -1 1 1 1 1 -1 1 1 1 ]

      I do not understand what you wrote about changing the data, but from what i posted i think you should be able to work out the seperate array issue which should put you well on your way.


      from the frivolous to the serious
        Thanks, maybe it me but I use ex. my @nloops = join(',',@{$collection[0]}); and try print @nloops[1] OUT [1,1,1,1,1] but the correct should be 1 To make this little test a more clear view from my part as you could see there are 4 array in the renderman rib ex. for ($i = 0; $i < array_length; $i ++ ) { print @params[0+$i] @params[1+$i] @params[2+$i] 1; } this would be output: -1 1 1 1 1 -1 1 1 1 ... next I apply a custom string in print "Run $count_lvert_length Poly\n"; for ($i = 0; $i < count_lverts*4; $i += 4 ) { if ( $lverts[0+($i/4)] == 3 ) { print "$lverts[0+($i/4)] < $vertid[2+$i] $vertid[1+$i] $vertid[0+$i]\n"; } else { print "$lverts[0+($i/4)] < $vertid[3+$i] $vertid[2+$i] $vertid[1+$i] $vertid[0+$i]\n"; } } append the end line !!! ---------------------------------- here is the 'renderman' rib example this file this what I read in and like to get data from # Starting polys PointsGeneralPolygons [1 1 1 1 1 1] [4 4 4 4 4 4] [ 0 4 5 1 1 5 6 2 2 6 7 3 3 7 4 0 3 0 1 2 4 7 6 5 ] "P" [ -0.5 -0.5 -0.5 0.5 -0.5 -0.5 0.5 -0.5 0.5 -0.5 -0.5 0.5 -0.5 0.5 -0.5 0.5 0.5 -0.5 0.5 0.5 0.5 -0.5 0.5 0.5 ] # Starting curves # Done curves --------------------------- and this is the code I trying to get Perl to make for me !!! -0.5 -0.5 -0.5 1 0.5 -0.5 -0.5 1 0.5 -0.5 0.5 1 -0.5 -0.5 0.5 1 -0.5 0.5 -0.5 1 0.5 0.5 -0.5 1 0.5 0.5 0.5 1 -0.5 0.5 0.5 1 Run 6 Poly 4 < 1 5 4 0 4 < 2 6 5 1 4 < 3 7 6 2 4 < 0 4 7 3 4 < 2 1 0 3 4 < 5 6 7 4 regards, Fredrik Gustafsson
        hi I'm not sure my message was send correct !!! here is the 'renderman' rib file. ----------------------------------- # Starting polys PointsGeneralPolygons [1 1 1 1 1 1] [4 4 4 4 4 4] [ 0 4 5 1 1 5 6 2 2 6 7 3 3 7 4 0 3 0 1 2 4 7 6 5 ] "P" [ -0.5 -0.5 -0.5 0.5 -0.5 -0.5 0.5 -0.5 0.5 -0.5 -0.5 0.5 -0.5 0.5 -0.5 0.5 0.5 -0.5 0.5 0.5 0.5 -0.5 0.5 0.5 ] # Starting curves # Done curves ------------------------------ and here is the code I like Perl to do for me. ------------------------------------------- -0.5 -0.5 -0.5 1 0.5 -0.5 -0.5 1 0.5 -0.5 0.5 1 -0.5 -0.5 0.5 1 -0.5 0.5 -0.5 1 0.5 0.5 -0.5 1 0.5 0.5 0.5 1 -0.5 0.5 0.5 1 Run 6 Poly 4 < 1 5 4 0 4 < 2 6 5 1 4 < 3 7 6 2 4 < 0 4 7 3 4 < 2 1 0 3 4 < 5 6 7 4 ------------------------------------- regards, Fredrik Gustafsson

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://234121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-07-29 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (226 votes), past polls