Esempio n. 1
0
def visualizeGFSName(gfsFileName,
                     outFileBase,
                     imgFormat='png',
                     cMap=ColorMap.BlackBodyMap(),
                     mapRange=1.0,
                     mapLimits=None,
                     sitesName=None,
                     obstacles=None):
    '''Visualizes a grid file sequence with the given color map.

    @param      gfsFileName     A string.  The name of the GridFileSequence to visualize.
    @param      outFileBase     A string.  The basic name of the images to be output.
                                For each grid in the sequence, it outputs outFileBase_###.imgFormat.
                                The path must already exist.
    @param      imgFormat       A string.  The output image format (png, jpg, or bmp )
    @param      cMap            An instance of ColorMap.  Indicates how the visualization works.
    @param      mapRange        A float.  Determines what fraction of the data range maps to the color
                                range.  For example, if mapRange is 0.75, then the value that is
                                75% of the way between the min and max value achieves the maximum
                                color value.  Ignored if mapLimits is not None.
    @param      mapLimits       A tuple which defines the map range independent of the real values in
                                the data (minVal, maxVal).  If the tuple has two values, that defines the range.
                                If either is None, then the corresponding value from the data is used.
    @param      sitesName       A string.  The path to a set of trajectory sites
    @param      obstacles       An instance of ObstacleSet (optional).  If obstacle are provided,
                                Then they will be drawn over the top of the data.
    '''
    reader = GFS.GridFileSequenceReader(gfsFileName)
    reader.setNext(0)
    try:
        sites = loadTrajectory(sitesName)
    except:
        sites = None
    visualizeGFS(reader, cMap, outFileBase, imgFormat, mapRange, mapLimits,
                 sites, obstacles)
Esempio n. 2
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 )
Esempio n. 3
0
 def makeVoronoi( grid ):
     print 'COMPUTING VORONOI!'
     pedFile = '/projects/crowd/fund_diag/paper/pre_density/experiment/Inputs/Corridor_onewayDB/dummy.txt'
     try:
         data = loadTrajectory( pedFile )
     except ValueError:
         print "Unable to recognize the data in the file: %s" % ( pedFile )
     frame, frameId = data.next()
     density = computeVoronoiDensity( grid, frame, data.getFrameIds() )
     grid.cells[ :, : ] = density.cells
 def test():
     from trajectory import loadTrajectory
     import os
     ##        obstPath = r'/projects/crowd/fund_diag/paper/pre_density/experiment/Inputs/Corridor_oneway/c240_obstacles.xml'
     ##        path = r'/projects/crowd/fund_diag/paper/pre_density/experiment/results/density/gaussian_S1.5/uo-065-240-240_combined_MB.density'
     ##        outPath = r'/projects/crowd/fund_diag/paper/pre_density/experiment/results/density/gaussian_S1.5/uo-065-240-240_combined_MB_density/'
     pedFile = r'/projects/crowd/fund_diag/paper/pre_density/experiment/Inputs/Corridor_onewayDB/uo-065-240-240_combined_MB.txt'
     try:
         frameSet = loadTrajectory(pedFile)
     except ValueError:
         print "Unable to recognize the data in the file: %s" % (pedFile)
     domain = AbstractGrid(Vector2(0.0, -6), Vector2(2.4, 12), (10, 100))
     gfs = GridFileSequence('sequence', arrayType=np.float32)
     gfs.computeVoronoiDensity(domain, frameSet, None)
Esempio n. 5
0
def testPedestrian():
    '''Test against legitimate pedestrian data'''
    # pedestrian domain
    minCorner = Vector2( 0.0, -6 )
    domainSize = Vector2( 2.4, 12 )
    pedDomain = Grid.RectDomain( minCorner, domainSize )
    # grid domain
    minCorner = Vector2( 0.0, -2 )
    domainSize = Vector2( 2.4, 4 )
    resolution = Vector2( domainSize.x / CELL_SIZE, domainSize.y / CELL_SIZE)
    gridDomain = Grid.AbstractGrid( minCorner, domainSize, resolution )

    # load pedestrian data
    pedFile = '/projects/crowd/fund_diag/paper/pre_density/experiment/Inputs/Corridor_onewayDB/uo-065-240-240_combined_MB.txt'
    try:
        data = loadTrajectory ( pedFile )
    except ValueError:
        print "Unable to recognize the data in the file: %s" % ( pedFile )
        return
    grids = []

    sig = Signals.PedestrianSignal( pedDomain )
    print gridDomain
    
    while ( True ):
        try:
            sig.setData( data )
        except StopIteration:
            break
        grid = gridDomain.getDataGrid() 
        kernel.convolve( sig, grid )
##        grid.cells /= ( CELL_SIZE * CELL_SIZE )

        print "Frame %d has min/max values: %f, %f" % ( sig.index, grid.minVal(), grid.maxVal() )        
        grids.append( grid )
##        break

    data.setNext( 0 )    
    visGrids( grids, data )
Esempio n. 6
0
def main():
    from GridFileSequence import GridFileSequence
    import optparse
    import sys, os
    import obstacles
    from trajectory import loadTrajectory
    parser = optparse.OptionParser()
    parser.set_description(
        'Compute a sequence of discrete voronoi diagrams for a trajectory file'
    )
    parser.add_option('-t',
                      '--trajectory',
                      help='The path to the trajectoroy data.',
                      action='store',
                      dest='trajFileName',
                      default='')
    parser.add_option('-x',
                      '--xDomain',
                      help='The extents of the region along x-axis',
                      nargs=2,
                      action='store',
                      type='float',
                      dest='xRange',
                      default=None)
    parser.add_option('-y',
                      '--yDomain',
                      help='The extents of the region along y-axis',
                      nargs=2,
                      action='store',
                      type='float',
                      dest='yRange',
                      default=None)
    parser.add_option(
        '-c',
        '--cellSize',
        help='The size of the cell size in the discretization. Default is 0.1',
        action='store',
        type='float',
        dest='cellSize',
        default=0.1)
    parser.add_option(
        '-o',
        '--output',
        help=
        'The path and base filename for the grid file sequence to be written -- no extension required. (Default is "output.voronoi").',
        action='store',
        dest='output',
        default='./output')
    parser.add_option(
        '-b',
        '--obstacles',
        help='Path to an obstacle xml file - not currently supported.',
        action='store',
        dest='obstXML',
        default=None)
    parser.add_option(
        '-d',
        '--density',
        help=
        'Indicates that the voronoi density should be computed and not the voronoi diagram',
        action='store_true',
        default=False,
        dest='density')
    options, args = parser.parse_args()

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

    if (options.xRange is None):
        print '\n *** You must specify the x-range'
        parser.print_help()
        sys.exit(1)

    if (options.yRange is None):
        print '\n *** You must specify the y-range'
        parser.print_help()
        sys.exit(1)

    folder, baseName = os.path.split(options.output)
    baseName, ext = os.path.splitext(baseName)
    # strip extension
    if (folder):
        if (not os.path.exists(folder)):
            os.makedirs(folder)

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

    minCorner = Vector2(options.xRange[0], options.yRange[0])
    size = Vector2(options.xRange[1] - minCorner[0],
                   options.yRange[1] - minCorner[1])
    rX = int(np.ceil(size[0] / options.cellSize))
    rY = int(np.ceil(size[1] / options.cellSize))
    size = Vector2(rX * options.cellSize, rY * options.cellSize)
    voronoiDomain = AbstractGrid(minCorner, size, (rX, rY))

    # currently assuming julich data for voronoi
    try:
        pedData = loadTrajectory(options.trajFileName)
    except ValueError:
        print "Unable to recognize the data in the file: %s" % (
            options.trajFileName)
        sys.exit(1)

    if (options.density):
        print 'Computing density voronoi'
        gfs = GridFileSequence(os.path.join(folder, baseName),
                               obstacles,
                               arrayType=np.float32)
        gfs.computeVoronoiDensity(voronoiDomain, pedData, obstacles)
    else:
        print 'Computing normal voronoi'
        gfs = GridFileSequence(os.path.join(folder, baseName),
                               obstacles,
                               arrayType=np.int32)
        gfs.computeVoronoi(voronoiDomain, pedData, obstacles)
Esempio n. 7
0
    def main():
        from GridFileSequence import GridFileSequenceReader
        import optparse
        import sys, os
        import obstacles
        from trajectory import loadTrajectory
        parser = optparse.OptionParser()
        parser.set_description(
            'Visualize a sequence of voronoi diagrams in a GridFileSequence')
        parser.add_option(
            '-i',
            '--input',
            help='A path to a grid file sequence - the data to visualize',
            action='store',
            dest='gfsName',
            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(
            '-e',
            '--extension',
            help='Image format: [png, jpg, bmp] (default is png)',
            action='store',
            dest='ext',
            default='png')
        parser.add_option(
            '-b',
            '--obstacles',
            help=
            '(Optional) Path to an obstacle xml file.  If provided, they will be drawn on top of the voronoi.',
            action='store',
            dest='obstXML',
            default=None)
        options, args = parser.parse_args()

        if (options.gfsName == ''):
            print '\n *** You must specify an input GridFileSequence file'
            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)

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

        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)

        reader = GridFileSequenceReader(options.gfsName)
        reader.setNext(0)

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

        drawVoronoiSeries(reader, options.output, trajData, obstacles)