Example #1
0
    def main():
        import optparse
        import ColorMap
        import sys, os
        import obstacles
        from trajectory import loadTrajectory
        parser = optparse.OptionParser()
        parser.add_option( '-i', '--input', help='A path to a grid file sequence - the data to visualize',
                           action='store', dest='input', default='' )
        parser.add_option( '-t', '--trajectory', help='(Optional) The path to the pedestrian data which produced the voronoi diagrams.',
                           action='store', dest='trajName', default=None )
        parser.add_option( '-o', '--output', help='The path and base filename for the output images (Default is "vis").',
                           action='store', dest='output', default='./vis' )
        parser.add_option( '-c', '--colorMap', help='Specify the color map to use.  Valid values are: %s.  Defaults to "black_body".' % ColorMap.getValidColorMaps(),
                           action='store', dest='cmapName', default='black_body' )
        parser.add_option( '-e', '--extension', help='Image format: [png, jpg, bmp] (default is png)',
                           action='store', dest='ext', default='png' )
        parser.add_option( '-b', '--obstacles', help='Path to an obstacle xml file',
                           action='store', dest='obstXML', default=None )
        options, args = parser.parse_args()

        if ( options.input == '' ):
            print '\n *** You must specify an input file'
            parser.print_help()
            sys.exit(1)

        try:
            colorMap = ColorMap.getColorMapByName( options.cmapName )
        except KeyError:
            print '\n *** You have selected an invalid color map: %s' % ( options.cmapName )
            parser.print_help()
            sys.exit(1)

        if ( not options.ext.lower() in ( 'png', 'jpg', 'bmp' ) ):
            print '\n *** You have selected an invalid file format: %s' % ( options.ext )
            parser.print_help()
            sys.exit(1)

        trajData = None
        if ( not options.trajName is None ):
            try:
                trajData = loadTrajectory( options.trajName )
            except ValueError:
                print "Unable to recognize the data in the file: %s" % ( options.trajName )

        folder, baseName = os.path.split( options.output )
        if ( folder ):
            if ( not os.path.exists( folder ) ):
                os.makedirs( folder )

        reader = GFS.GridFileSequenceReader( options.input )
        reader.setNext( 0 )    

        obstacles = None
        if ( options.obstXML ):
            obstacles, bb = obstacles.readObstacles( options.obstXML )

        visualizeGFS( reader, colorMap, options.output, options.ext, 1.0, trajData, obstacles )