def __init__(self, positions, min_value=0, max_value=1, normalize=False, noise=None, shape=None): ''' :param positions: 2D positions of the sensels ''' if normalize: logger.warning('normalize=True is deprecated') if shape is None: shape = [len(positions)] self.num_sensels = len(positions) self.positions = np.array(positions) self.min_value = min_value self.max_value = max_value self.normalize = normalize self.noise_spec = noise self.noise = (None if self.noise_spec is None else instantiate_spec(self.noise_spec)) boot_spec = { 'desc': 'Field sampler', 'shape': shape, 'format': 'C', 'range': [float(self.min_value), float(self.max_value)], 'extra': {'positions': self.positions.tolist(), 'normalize': bool(normalize), 'max_value': float(max_value), 'min_value': float(min_value), 'noise': self.noise_spec} } VehicleSensor.__init__(self, boot_spec) self.primitives = None
from vehicles_cairo import vehicles_has_cairo if not vehicles_has_cairo: logger.error('This program cannot run if Cairo is not installed.') return from vehicles_cairo import ... ''' from vehicles import __version__, logger try: import cairo # @UnresolvedImport vehicles_has_cairo = True except ImportError as e: cairo_error = e vehicles_has_cairo = False logger.warning('Could not import PyCairo; visualization not available.') from .constants import * from .utils import * from .skins import * from .world_geometry import * from .sensor_data import * from .display_all import * from .write_to_file import *
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)
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)