Пример #1
0
def main():
    if not vehicles_has_cairo:
        logger.error('This program cannot be run if Cairo is not installed.')
        return
    from vehicles_cairo import (cairo_plot_rectangle)
    from vehicles_cairo import  cairo_plot_circle, cairo_set_axis, show_grid

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--outdir", "-o", default='.',
                    help="output directory [%default]")

#    parser.add_option("--outdir", "-o", default='.',
#                    help="additional config directory [%default]")

    (options, args) = parser.parse_args()
    if args:
        raise Exception()

    width = 400
    height = 400

    r = Report('skins_demo')
    f = r.figure(cols=3)

    import cairo

    VehiclesConfig.make_sure_loaded()

    skins = get_conftools_skins().keys()
    logger.info('Skins: %s' % skins)
    for id_skin in skins:
        skin = get_conftools_skins().instance(id_skin)
        with f.data_file(id_skin, MIME_PNG) as filename:
            surf = cairo.ImageSurface(cairo.FORMAT_ARGB32,  # @UndefinedVariable 
                                      width, height)
            cr = cairo.Context(surf)  # @UndefinedVariable
            cairo_plot_rectangle(cr, 0, 0, width, height, fill_color=[1, 1, 1])

            cairo_set_axis(cr, width, height, [-2, +2, -2, +2])

            cairo_plot_circle(cr, center=[0, 0], radius=1, facecolor=None,
                    edgecolor=(1, 0, 0), width=0.1)

            show_grid(cr, bx=[-3, +3], by=[-3, +3], spacing=1.0)

            if skin.njoints_required() > 1:
                logger.warning('Skipping skin %r' % id_skin)
                continue

            try:
                skin.draw(cr, joints=[])
            except Exception:
                logger.error('Error for skin %r' % id_skin)
                raise

            surf.write_to_png(filename)  # Output to PNG

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)
Пример #2
0
 def info(self, s):
     logger.info(s)  # XXX
Пример #3
0
def inspect_textures():
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("-w", "--world", default='stochastic_box_10',
                       help="ID world [%default].")

    parser.add_option("-n", default=1, type='int',
                    help="number of simulations [%default].")
    parser.add_option("--outdir", "-o", default='out-inspect_textures',
                    help="output directory [%default]")
    parser.add_option("--figsize", default=1, type='float',
                    help="figsize (inches) [%default]")
    parser.add_option("-z", "--zoom", default=0, type='float',
                    help="zoom in meters; 0 for full view [%default]")

    (options, args) = parser.parse_args()
    if args:
        raise Exception()  # XXX

    id_world = options.world

    logger.info('  id_world: %s' % id_world)

    world = VehiclesConfig.worlds.instance(id_world)  # @UndefinedVariable

    from reprep import Report
    basename = 'inspect_textures-%s' % (id_world)
    r = Report(basename)

    for i in range(options.n):
        sec = r.node('simulation%d' % i)
        world.new_episode()
        primitives = world.get_primitives()
        for p in primitives:
            psec = sec.node('%s_%d' % (p.__class__.__name__, p.id_object))
            psec.text('object', pformat(p.to_yaml()))

            f = psec.figure(cols=2)
            if not isinstance(p, GeometricShape):
                continue

            perimeter = p.get_perimeter()
            texture = instantiate_spec(p.texture)

            chunk_size = 10
            nchunks = np.ceil(perimeter * 1.0 / chunk_size)

            for c in range(int(nchunks)):
                xfrom = c * chunk_size
                xto = np.minimum(perimeter, xfrom + chunk_size)
                N = 1000
                x = np.linspace(xfrom, xto, N)

                lum = texture(x)

                with f.plot('chunk%s' % c,
                              figsize=(options.figsize * 10,
                                      options.figsize)) as pylab:
                    pylab.plot(x, lum)
                    pylab.axis((xfrom, xfrom + chunk_size, -0.1, 1.1))

#
#        if False:
#            with f.data_pylab('pdf', mime=MIME_PDF,
#                              figsize=(options.figsize,
#                                      options.figsize)) as pylab:
#                    display_all(pylab, sim_state, grid=1, zoom=0, 
# show_sensor_data = True)
#            f.last().add_to(f)

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)
Пример #4
0
 def info(self, s):
     logger.info(s)  # XXX
Пример #5
0
def main():
    if not vehicles_has_cairo:
        logger.error('This program cannot be run if Cairo is not installed.')
        return
    from vehicles_cairo import (cairo_plot_rectangle)
    from vehicles_cairo import cairo_plot_circle, cairo_set_axis, show_grid

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--outdir",
                      "-o",
                      default='.',
                      help="output directory [%default]")

    #    parser.add_option("--outdir", "-o", default='.',
    #                    help="additional config directory [%default]")

    (options, args) = parser.parse_args()
    if args:
        raise Exception()

    width = 400
    height = 400

    r = Report('skins_demo')
    f = r.figure(cols=3)

    import cairo

    VehiclesConfig.make_sure_loaded()

    skins = get_conftools_skins().keys()
    logger.info('Skins: %s' % skins)
    for id_skin in skins:
        skin = get_conftools_skins().instance(id_skin)
        with f.data_file(id_skin, MIME_PNG) as filename:
            surf = cairo.ImageSurface(
                cairo.FORMAT_ARGB32,  # @UndefinedVariable 
                width,
                height)
            cr = cairo.Context(surf)  # @UndefinedVariable
            cairo_plot_rectangle(cr, 0, 0, width, height, fill_color=[1, 1, 1])

            cairo_set_axis(cr, width, height, [-2, +2, -2, +2])

            cairo_plot_circle(cr,
                              center=[0, 0],
                              radius=1,
                              facecolor=None,
                              edgecolor=(1, 0, 0),
                              width=0.1)

            show_grid(cr, bx=[-3, +3], by=[-3, +3], spacing=1.0)

            if skin.njoints_required() > 1:
                logger.warning('Skipping skin %r' % id_skin)
                continue

            try:
                skin.draw(cr, joints=[])
            except Exception:
                logger.error('Error for skin %r' % id_skin)
                raise

            surf.write_to_png(filename)  # Output to PNG

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)
Пример #6
0
def main():
    from vehicles_cairo import vehicles_has_cairo
    if not vehicles_has_cairo:
        logger.error('This program cannot be run if Cairo is not installed.')
        return

    from vehicles_cairo import (vehicles_cairo_display_pdf,
                                vehicles_cairo_display_png,
                                vehicles_cairo_display_svg,
                                cairo_plot_circle2)

    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("--vehicles", default='*',
                      help="ID vehicle [%default].")
    parser.add_option("--world", default='SBox2_10a',
                      # default='empty_fixed',
                       help="ID world [%default].")
    parser.add_option("--outdir", "-o",
                      default='vehicles_demo_display_vehicles',
                    help="output directory [%default]")
    parser.add_option("--figsize", default=10, type='float',
                    help="figsize (inches) [%default]")
    parser.add_option("-g", "--grid", default=1, type='float',
                    help="grid size in meters; 0 for no grid [%default]")
    parser.add_option("-d", dest="config", default=".",
                      help="Config directory")
    parser.add_option("--scale", default=False, action='store_true',
                    help="If given, displays the scale with a red circle")

    (options, args) = parser.parse_args()
    if args:
        raise Exception()  # XXX

    id_world = options.world

    logger.info('  id_world: %s' % id_world)

    from reprep import Report, MIME_PDF
    basename = 'vehicles_demo'
    r = Report(basename)

    logger.info('Loading configuration from %s' % options.config)
    VehiclesConfig.load(options.config)

    # TODO: selection
    all_vehicles = VehiclesConfig.vehicles.keys()
    if options.vehicles is None:
        vehicles = all_vehicles
    else:
        vehicles = expand_string(options.vehicles, all_vehicles)

    print('Plotting vehicles: %s' % vehicles)

    f0 = r.figure(cols=6)
    f0_data = r.figure(cols=6)

    for id_vehicle in sorted(vehicles):
        sec = r.node(id_vehicle)
        f = sec.figure(cols=6)

        world = VehiclesConfig.specs['worlds'].instance(id_world)
        vehicle = VehiclesConfig.specs['vehicles'].instance(id_vehicle)
        simulation = VehicleSimulation(vehicle, world)
        simulation.new_episode()
        simulation.compute_observations()
        sim_state = simulation.to_yaml()

        def draw_scale(cr):
            if options.scale:
                cairo_plot_circle2(cr, 0, 0,
                               vehicle.radius, fill_color=(1, .7, .7))

        plot_params = dict(grid=options.grid,
                           zoom=1.5,
                           zoom_scale_radius=True,
                           width=500, height=500,
                           show_sensor_data=True,
                           show_sensor_data_compact=True,
                           extra_draw_world=draw_scale,
                           bgcolor=None,
                           show_world=False)

        with f.data_file('png_with', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                        sim_state=sim_state, **plot_params)

        f0_data.sub(f.last(), caption=id_vehicle)

        plot_params['show_sensor_data'] = False
        with f.data_file('png_without', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                        sim_state=sim_state, **plot_params)

        f0.sub(f.last(), caption=id_vehicle)

        with f.data_file('svg', MIME_SVG) as filename:
            vehicles_cairo_display_svg(filename,
                        sim_state=sim_state, **plot_params)

        plot_params['grid'] = 0
        plot_params['extra_draw_world'] = None
        with sec.data_file('pdf', MIME_PDF) as filename:
            vehicles_cairo_display_pdf(filename,
                        sim_state=sim_state, **plot_params)

        plot_params['show_robot_body'] = True
        plot_params['show_robot_sensors'] = False
        with f.data_file('png_only_body', MIME_PNG) as filename:
            vehicles_cairo_display_png(filename,
                        sim_state=sim_state, **plot_params)

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)
Пример #7
0
def inspect_textures():
    parser = OptionParser(usage=usage)
    parser.disable_interspersed_args()

    parser.add_option("-w",
                      "--world",
                      default='stochastic_box_10',
                      help="ID world [%default].")

    parser.add_option("-n",
                      default=1,
                      type='int',
                      help="number of simulations [%default].")
    parser.add_option("--outdir",
                      "-o",
                      default='out-inspect_textures',
                      help="output directory [%default]")
    parser.add_option("--figsize",
                      default=1,
                      type='float',
                      help="figsize (inches) [%default]")
    parser.add_option("-z",
                      "--zoom",
                      default=0,
                      type='float',
                      help="zoom in meters; 0 for full view [%default]")

    (options, args) = parser.parse_args()
    if args:
        raise Exception()  # XXX

    id_world = options.world

    logger.info('  id_world: %s' % id_world)

    world = VehiclesConfig.worlds.instance(id_world)  # @UndefinedVariable

    from reprep import Report
    basename = 'inspect_textures-%s' % (id_world)
    r = Report(basename)

    for i in range(options.n):
        sec = r.node('simulation%d' % i)
        world.new_episode()
        primitives = world.get_primitives()
        for p in primitives:
            psec = sec.node('%s_%d' % (p.__class__.__name__, p.id_object))
            psec.text('object', pformat(p.to_yaml()))

            f = psec.figure(cols=2)
            if not isinstance(p, GeometricShape):
                continue

            perimeter = p.get_perimeter()
            texture = instantiate_spec(p.texture)

            chunk_size = 10
            nchunks = np.ceil(perimeter * 1.0 / chunk_size)

            for c in range(int(nchunks)):
                xfrom = c * chunk_size
                xto = np.minimum(perimeter, xfrom + chunk_size)
                N = 1000
                x = np.linspace(xfrom, xto, N)

                lum = texture(x)

                with f.plot('chunk%s' % c,
                            figsize=(options.figsize * 10,
                                     options.figsize)) as pylab:
                    pylab.plot(x, lum)
                    pylab.axis((xfrom, xfrom + chunk_size, -0.1, 1.1))


#
#        if False:
#            with f.data_pylab('pdf', mime=MIME_PDF,
#                              figsize=(options.figsize,
#                                      options.figsize)) as pylab:
#                    display_all(pylab, sim_state, grid=1, zoom=0,
# show_sensor_data = True)
#            f.last().add_to(f)

    filename = os.path.join(options.outdir, 'index.html')
    logger.info('Writing to %r.' % filename)
    r.to_html(filename)