source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vrippack-0.31/src/plytools/ply2bboxcube @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

  • Property svn:executable set to *
File size: 2.3 KB
Line 
1#!/usr/bin/perl
2#
3# plybbox2cube:
4#    This script takes the output of plybbox and generates a
5# ply file with the actual faces of a cube for the bounding
6# box.
7#
8# usage:
9#   (see below)
10
11sub printUsage {
12    print STDERR "\n";
13    print STDERR "Usage: ply2bboxcube in1.ply [in2.ply] ...\n";
14    print STDERR "\n";
15    print STDERR "And it will generate files called in1.bboxcube.ply,\n";
16    print STDERR "in2.bboxcube.ply, etc.....\n";
17    print STDERR "Which contain all 12 faces of the bounding box.\n";
18    print STDERR "\n";
19    exit -1;
20}
21
22if ($#ARGV == -1 || substr($ARGV[0], 0, 1) eq "-") {
23    &printUsage();
24
25} else {
26    for ($i = 0; $i <= $#ARGV; $i++) {
27        $inname = $ARGV[$i];
28        # Check to make sure it ends in .ply
29        if (substr($inname, -4, 4) ne ".ply") {
30            print STDERR "Err, $inname does not end in .ply, skipping...\n";
31            next;
32        }
33        # open the input file
34        if (!open(IN, $inname)) {
35            print STDERR "Err, cannot open input ply file $inname, ".
36                "skipping....\n";
37            next;
38        }
39        #compute output file, make sure we're not overwriting input
40        $outname = $inname;
41        $outname =~ s/.ply/.bboxcube.ply/g;
42        if ($outname eq $inname) {
43            print STDERR "Assertion failure. $outname == $inname? skipping.\n";
44            next;
45        }
46       
47        # open output file
48        if (!open(OUT, ">$outname")) {
49            print STDERR "Err, annot open output ply file $outname, ".
50                "skipping....\n";
51            next;
52        }
53
54        # Run it
55        close(IN);
56        ($minx, $miny, $minz, $maxx, $maxy, $maxz) = 
57            split(' ', `plybbox $inname`);
58        &plybboxcreatecube($inname, OUT);
59        close(OUT);
60    }
61}
62
63sub plybboxcreatecube {
64    # Assume that these variables have been defined:
65    # $minx, $miny, $minz
66    # $maxx, $maxy, $maxz
67
68    #
69    #       3-----------1
70    #      /|          /|    Z
71    #     5-----------7 |    |
72    #     | |         | |    |  Y
73    #     | 6---------|-4    | /
74    #     |/          |/     |/
75    #     0-----------2      --------X
76    #
77
78    print OUT
79"ply
80format ascii 1.0
81element vertex 8
82property float x
83property float y
84property float z
85element face 12
86property list uchar int vertex_indices
87end_header
88$minx $miny $minz
89$maxx $maxy $maxz
90$maxx $miny $minz
91$minx $maxy $maxz
92$maxx $maxy $minz
93$minx $miny $maxz
94$minx $maxy $minz
95$maxx $miny $maxz
963 0 2 5
973 5 2 7
983 2 4 7
993 7 4 1
1003 4 6 1
1013 1 6 3
1023 6 0 5
1033 6 5 3
1043 5 7 3
1053 3 7 1
1063 6 4 2
1073 6 2 0
108";
109}
Note: See TracBrowser for help on using the repository browser.