---------------------------------------------------------

Inventor/VRML 2 PtSet

---------------------------------------------------------
Note: Running this Script on NT will need some minor modifications. Changes needed are mentioned in the source. Only Accepts Inventor ASCII/VRML Files Currently. Especially useful if you are on a SGI system. Use ivcat on a SGI System to convert Inventor Binary files to Ascii format.

 

#!/usr/bin/perl

#------------------------------------------------------
# Perl Routine to extract vertices from a
# Inventor/VRML File.
# My First PerlScript !
#------------------------------------------------------


if($#ARGV != 1){
   print "\n$0 Rips a Inventor File and Outputs its point set\n";
   print "Usage: $0 [.iv/.wrl File] [Output Point Set File]\n\n";
   print "Currently only Accepts Inventor Ascii Format.\n";
   print "Use SGI's ivcat to convert any binary Inventor File to ASCII\n\n";
   print "Missing Object Number represent Texture Co-ordinates\n";
   print "sort command should be in the path to run iv2dat.pl\n";
   exit(1);
}  


#---------------------------
# Process one Input Line
#---------------------------
# Outputs xyz coordinates
# in Output File Specified
#---------------------------

$token = 0; # 3 tokens per output line
sub prline(){
    @List = split(/[\s|\n]+/,$line);
    if($#List > 1){
    foreach $x(@List){
     if ($x =~ m/[+-0123456789.]/m) {
    print Outfile "$x ";
    $token++;
 }
        if($token == 3){
       print Outfile "\n";
       $token = 0;
       $segp++;
        }
    }
    }
}


#---------------------------
# Program Starts here...
#---------------------------

# Global Variables
$segn = 1;
$segp = 0;
$totp = 0;
$| = 1;
$line = "Ripping Points from $ARGV[0]...\n";

# Open your files
open(Inpfile,$ARGV[0])
 or die "Could not Open Input File:\n\t $!";

# For Windows replace the following line
# with open(Outfile," >$ARGV[1]")

open(Outfile,"|sort -u >$ARGV[1]")
  or die "Could not Open Sorted Output Stream:\n\t $!";


# Print that I'm at work
print "$line";

# Start reading your Input
# Warning: Does not check
# Input Existence or Output
# File Opened Properly or not.

while(<Inpfile>){
LoopBegin:
    if(/(^|\s+)point[\s\[]+/){
    #  Point List starts
       do {
  # All points come here
  $line = $_;
  $line =~ tr/0-9e' ''.''\-'','//cd;
  $line =~ tr/','/' '/d;
  prline;
         if(/\]/){ # is it the last point line
            # of this point definition
     # Last Point of this set
     print "\tRipped Object[$segn]:$segp Points inserted\n" if $segp != 0;
     $totp += $segp;
     $segp = 0;
     $segn++;
     goto LoopBegin;
  }
       }while(<Inpfile>);
 
    } # main if that detects point tag
}

close Outfile;
close InpFile;
print "\nConversion Done\nTotal Points :\n";
print "\tInput :\t  $totp\n";
print "\tOutput:";
# Comment the following line on Windows.
exec "wc -l <$ARGV[1]"

---------------------------------------------------------

Mirrored at Compgeom.com, AMS-StonyBrook. Valid HTML 4.0! Valid CSS! My Home Page

This page is being written to HTML 4.0 specifications and has been entirely hand coded
for interoperability. Here are the links of the pages that helped in designing this page.
Copyright © 1997-2000 Piyush Kumar

---------------------------------------------------------