def display_empty_scene_with_GUI(GUI, scene_attributes=rtneuron.AttributeMap(), *args, **kwargs): """Initializes an RTNeuron instance with a GUI overlay and an empty scene. The gui parameter is a class that must inherit from rtneuron.gui.BaseGUI. An object of this class will be instantiated to create the overlay what will appear on top of the 3D rendering. The basic sequence of operations is as follows: - The QApplication is created. - The GUI is instantiated. - The RTNeuron engine object is created and linked to the GUI. - An empty scene is displayed. The return value is the instance of the GUI class. The RTNeuron engine is set into the rtneuron.engine global variable. The *args and **kwargs arguments are passed to the GUI constructor. """ qt_app = create_qt_app() # lgtm [py/unused-local-variable] # We need the QtApplication object in a local # variable until the scoped is finished gui = GUI(*args, **kwargs) rtneuron.display_empty_scene( scene_attributes=scene_attributes, opengl_share_context=gui.get_background_context()) gui.connect_engine(rtneuron.engine) return gui
def _on_load_dialog_done(self, simulation, circuit, gids, display_mode): _rtneuron.simulation = simulation # Closing the dialog self.loader.close() self._simulation = simulation # Adding the targets to the scene view = _rtneuron.engine.views[0] scene = view.scene scene.circuit = circuit self.progress = Progress(self._overlay) self.progress.done.connect(self._on_progress_done) scene.progress.connect(self.progress.step) self.progress.set_message("Loading data") attributes = _rtneuron.AttributeMap() if display_mode == "Soma": attributes.mode = _rtneuron.RepresentationMode.SOMA elif display_mode == "No axon": attributes.mode = _rtneuron.RepresentationMode.NO_AXON elif display_mode == "Detailed": attributes.mode = _rtneuron.RepresentationMode.WHOLE_NEURON scene.addNeurons(gids, attributes) # If something was typed in the loader dialog the base overlay has # lost the focus. Returning the focus because otherwise key presses # won't be captured. self._overlay.rootObject().setProperty("focus", True)
def test_attributes(self): self.view.attributes.auto_adjust_model_scale = True self.assertRaises(RuntimeError, setattr, self.view.attributes, "auto_adjust_model_scale", 10) self.view.attributes.auto_compute_home_position = True self.assertRaises(RuntimeError, setattr, self.view.attributes, "auto_compute_home_position", -1) self.view.attributes.background = [1, 1, 1] self.assertRaises(RuntimeError, setattr, self.view.attributes, "background", [1, 1]) self.view.attributes.clod_threshold = 2000 self.assertRaises(RuntimeError, setattr, self.view.attributes, "clod_threshold", 'wrong') self.assertRaises(RuntimeError, setattr, self.view.attributes, "auto_compute_home_position", 10) self.assertRaises(RuntimeError, setattr, self.view.attributes, "idle_AA_steps", 'foo') self.view.attributes.inflation_factor = 5 self.view.attributes.inflation_factor = 0 self.assertRaises(RuntimeError, setattr, self.view.attributes, "inflation_factor", 'toto') self.assertRaises(RuntimeError, setattr, self.view.attributes, "inflation_factor", -2) self.view.attributes.lod_bias = 2 self.assertRaises(RuntimeError, setattr, self.view.attributes, "lod_bias", 'wrong') self.view.attributes.output_file_prefix = 'prefix' self.assertRaises(RuntimeError, setattr, self.view.attributes, "output_file_prefix", False) self.view.attributes.output_file_format = 'giff' self.assertRaises(RuntimeError, setattr, self.view.attributes, "output_file_prefix", 10.0) self.view.attributes.probe_color = [1, 1, 1] self.view.attributes.probe_color = [1, 1, 1, 1] self.assertRaises(RuntimeError, setattr, self.view.attributes, "probe_color", [1, 1]) self.view.attributes.probe_threshold = 40 self.assertRaises(RuntimeError, setattr, self.view.attributes, "probe_threshold", rtneuron.AttributeMap()) self.view.attributes.snapshot_at_idle = False self.assertRaises(RuntimeError, setattr, self.view.attributes, "snapshot_at_idle", 10) self.view.attributes.spike_tail = 10000.0 self.assertRaises(RuntimeError, setattr, self.view.attributes, "spike_tail", 'bad') self.view.attributes.stereo = True self.assertRaises(RuntimeError, setattr, self.view.attributes, "stereo", -1) self.view.attributes.stereo_correction = 1.4 self.assertRaises(RuntimeError, setattr, self.view.attributes, "stereo_correction", 'no') self.view.attributes.use_roi = True self.assertRaises(RuntimeError, setattr, self.view.attributes, "use_roi", -0xBAD) self.view.attributes.zero_parallax_distance = -111 self.assertRaises(RuntimeError, setattr, self.view.attributes, "zero_parallax_distance", 'error') self.assertRaises(RuntimeError, setattr, self.view.attributes, "testing_at_least_one_unknown_attribute", 10)
def test_attributes(self): attributes = rtneuron.AttributeMap() attributes.foo = False assert(attributes.foo == False) attributes.foo = 10 assert(attributes.foo == 10) attributes.foo = 10.0 assert(attributes.foo == 10.0) attributes.foo = 'string' assert(attributes.foo == 'string') attributes.blah = [0, 1, 2] assert(attributes.blah == [0, 1, 2]) attributes == rtneuron.AttributeMap({'foo': 'string', 'blah': [0, 1, 2]}) assert (attributes.__str__() == "blah: 0 1 2\nfoo: string\n") assert(dir(attributes) == ['blah', 'foo']) attributes.help()
def test_attribute_changed_signal(self): attributes = rtneuron.AttributeMap() def callback(name): self._name = name self._value = attributes.__getattr__(name) attributes.attributeChanged.connect(callback) attributes.test = 10 assert (self._name == "test") assert (self._value == 10)
def __init__(self, *args, **kwargs): attributes = _rtneuron.AttributeMap() # Don't use meshes because branch level culling of the meshes from the # default circuit provides terrible results on meshes. attributes.use_meshes = False attributes.inflatable_neurons = True self._gui = display_empty_scene_with_GUI( GUI, attributes, *args, **kwargs) view = _rtneuron.engine.views[0] view.attributes.auto_compute_home_position = False view.attributes.background = [1, 1, 1, 1] view.attributes.highlight_color = [1, 0.8, 0, 1]
def setUp(self): attributes = rtneuron.AttributeMap( {'mode': rtneuron.RepresentationMode.WHOLE_NEURON}) setup.setup_simple(self, 'L5CSPC', target_attributes = attributes) self.view = self.engine.views[0] self.view.auto_compute_home_position = False self.view.scene = self.scene # To make sure the scene is ready before the timestamps are modified self.engine.frame() self.engine.frame() position = [30, 600, 300] orientation = ([0, 0, 1], 0) self.view.camera.setView(position,orientation)
def __init__(self, *args, **kwargs): attributes = _rtneuron.AttributeMap() # Don't use meshes because this tool is going to be used with circuits # that lack them attributes.use_meshes = False self._gui = display_empty_scene_with_GUI( GUI, attributes, *args, **kwargs) view = _rtneuron.engine.views[0] view.attributes.auto_compute_home_position = False view.attributes.auto_adjust_model_scale = False view.attributes.background = [0, 0, 0, 0] view.attributes.highlight_color = [1, 0.8, 0, 1]
def _on_model_add(self, name): try: attributes = _rtneuron.AttributeMap() attributes.color = [1, 1, 1, 1] handle = self._scene.addModel(str(name), attributes=attributes) except RuntimeError as e: self._qml.showError(str(e)) return view = _rtneuron.engine.views[0] view.computeHomePosition() self._modelList.add(name, "#ffffffff") self._handles.append(handle)
def _display_connection_synapses(self, synapses): self._remove_all_synapses() self._engine.frame() pre, post = self._cell_pair.gids attributes = _rtneuron.AttributeMap() attributes.radius = self._synapse_radius attributes.color = self._synapse_colors[0] self._synapse_handlers[pre] = \ self._scene.addEfferentSynapses(synapses, attributes)\ attributes.color = self._synapse_colors[1] self._synapse_handlers[post] = \ self._scene.addAfferentSynapses(synapses, attributes)
def __init__(self, *args, **kwargs): attributes = _rtneuron.AttributeMap() # Don't use meshes because branch level culling of the meshes from the # default circuit provides terrible results on meshes. attributes.use_meshes = False # We want circuit building to assume that there are no morphologies to # speed it up. attributes.load_morphologies = False attributes.inflatable_neurons = True self._gui = display_empty_scene_with_GUI(GUI, attributes, *args, **kwargs) view = _rtneuron.engine.views[0] view.attributes.auto_compute_home_position = False view.attributes.auto_adjust_model_scale = False view.attributes.background = [1, 1, 1, 1] view.attributes.highlight_color = [1, 0.8, 0, 1]
def _on_update(self, scheme, primary, secondary, attenuation): scene = _rtneuron.engine.views[0].scene handler = scene.objects[0] if scheme == "0": scheme = _rtneuron.ColorScheme.SOLID elif scheme == "1": scheme = _rtneuron.ColorScheme.BY_WIDTH elif scheme == "2": scheme = _rtneuron.ColorScheme.BY_DISTANCE_TO_SOMA elif scheme == "3": scheme = _rtneuron.ColorScheme.BY_BRANCH_TYPE else: print("Unknown color scheme requested") return handler.attributes.color_scheme = scheme if not hasattr(handler.attributes, "extra"): handler.attributes.extra = _rtneuron.AttributeMap() handler.attributes.extra.attenuation = attenuation handler.attributes.primary_color = [ primary.redF(), primary.greenF(), primary.blueF(), primary.alphaF() ] handler.attributes.secondary_color = [ secondary.redF(), secondary.greenF(), secondary.blueF(), secondary.alphaF() ] if primary.alphaF() != 1.0 or secondary.alphaF() != 1.0: _rtneuron.sceneops.enable_transparency(scene) else: _rtneuron.sceneops.disable_transparency(scene) handler.update()
def test_color_map(self): attributes = rtneuron.AttributeMap() attributes.colormap = rtneuron.ColorMap() points = {0: (0.0, 0.0, 0.0, 0.0), 1: (1.0, 1.0, 1.0, 1.0)} attributes.colormap.setPoints(points) assert (attributes.colormap.getPoints() == points)
def test_creation_with_args_and_attributes(self): attributes = rtneuron.AttributeMap({'soma_radius': 10}) engine = rtneuron.RTNeuron(sys.argv, attributes)
def test_creation_with_attributes(self): attributes = rtneuron.AttributeMap({'soma_radius': 10}) engine = rtneuron.RTNeuron(attributes=attributes)
def _pick_first_cell(self, gid): to_pick = self._cell_to_pick def other(cell_to_pick): return 1 - cell_to_pick neurons = self._scene.objects[0] # Loading synapses circuit = self._scene.circuit if to_pick == self.POSTSYNAPTIC_CELL: synapses = circuit.afferent_synapses([gid]) else: synapses = circuit.efferent_synapses([gid]) self._synapses = synapses # Hiding all the cells neurons.attributes.mode = _rtneuron.RepresentationMode.NO_DISPLAY neurons.update() # Highlighting the cell picked and displaying it in detailed mode. selected = neurons.query([gid]) selected.attributes.mode = \ _rtneuron.RepresentationMode.WHOLE_NEURON selected.attributes.color_scheme = _rtneuron.ColorScheme.SOLID selected.attributes.primary_color = self._cell_colors[to_pick] selected.update() # Make sure the cell is unclipped at this point. selected.apply(_NeuronClipping().unclipAll()) # Finding the connected cells and grouping the synapses per connection. if to_pick == self.PRESYNAPTIC_CELL: connected = synapses.post_gids() else: connected = synapses.pre_gids() connected = _np.unique(connected) connections = dict() for i in connected: pre = [gid if to_pick == self.PRESYNAPTIC_CELL else int(i)] post = [int(i) if to_pick == self.PRESYNAPTIC_CELL else gid] connections[i] = circuit.projected_synapses(pre, post) # Setting the mask for making only the connected cells selectable. mask = _np.setdiff1d(neurons.object, connected) self._base_selection_mask = mask connected = neurons.query(connected) # Adding one synapes set per connection. Doing this instead # of adding a single set makes it easier to apply a different color # to each synapse subset. functors = [_rtneuron.Scene.addEfferentSynapses, _rtneuron.Scene.addAfferentSynapses] attributes = _rtneuron.AttributeMap() attributes.radius = self._synapse_radius self._synapse_handlers = dict() _rtneuron.engine.pause() for key, synapses in connections.items(): self._synapse_handlers[key] = \ functors[to_pick](self._scene, synapses, attributes) _rtneuron.engine.resume() # Applying the coloring based on the user selection self._coloring_handler.set_target_cells( connected, self._cell_colors[other(to_pick)], visible=self._show_connected_cells) self._coloring_handler.set_target_synapses( self._synapse_handlers, self._synapse_colors[to_pick]) self._coloring_handler.colorize() # Updating state variables self._cell_pair.handlers[to_pick] = selected self._cell_pair.gids[to_pick] = gid self._connected_cells = connected self._cell_to_pick = other(to_pick) self._update_connection_info.emit() self._connected_cells_hideable.emit(True) # Setting the new home position for the view position = list(map(float, circuit.positions([gid])[0])) view = _rtneuron.engine.views[0] view.cameraManipulator.setHomePosition( view.camera.getView()[0], position, [0, 1, 0])