def make_front_ortho(view, **kwargs): """Setup the camera projection and position of the given view to do an orthographic front projection of the neurons on its scene. """ options = _CommonOptions(**kwargs) scene = view.scene circuit = scene.circuit gids = _numpy.zeros((0), dtype="u4") for object in scene.objects: if _rtneuron.sceneops.is_neuron_handler(object): gids = _numpy.append(gids, object.object) view.camera.makeOrtho() ortho = view.camera.getProjectionOrtho() aspect_ratio = (ortho[1] - ortho[0]) / (ortho[3] - ortho[2]) xys = options.fit_point_generator(gids, circuit)[:, [0, 1]] ortho = _numpy.array( _ortho_frustum(xys, aspect_ratio=aspect_ratio, **kwargs)) view.camera.setProjectionOrtho(*(ortho / view.attributes.model_scale), near=1) path = _neurons_front_view(gids, circuit, aspect_ratio=aspect_ratio, **kwargs) keyframe = path.getKeyFrames()[0][1] view.camera.setView(keyframe.position, keyframe.orientation)
def front_ortho(simulation, targets, **kwargs): """Return the frustum parameters for an orthogonal front view of a cell target. This function will load a simulation configuration file to get the soma position of the neurons given their gids. The frustum size is computed based only on these positions. In order to frame the scene correctly an additional camera path has to be set up. The target parameter can be: - A cell GID (as integer) - A numpy array of u4, u8 or i4 - A target labels (as a string) - A list of any of the above """ options = _CommonOptions(**kwargs) simulation = _brain.Simulation(simulation) circuit = simulation.open_circuit() gids = _rtneuron.util.targets_to_gids(targets, simulation) xys = options.fit_point_generator(gids, circuit)[:, [0, 1]] return _ortho_frustum(xys, **kwargs)
def flythrough(simulation, targets, duration=10, **kwargs): """Return a camera path of a flythrough of a cell target. This function will load the simulation config file given and all the neurons associated with the target specification. The camera position is computed based only on the soma positions and corresponds to a front view of the circuit. The path duration must be in seconds. The targets parameter can be: - A cell GID (as integer) - An iterable of GIDs - A target labels (as a string) - A list of any of the above The optional keyword arguments are: - samples: Number of keyframes to generate - speedup: From 1 to inf, this parameter specifies a speed up for the initial camera speed. Use 1 for a linear camera path, if higher that one the camera will start faster and will decrease its speed non-linearly and monotonically. Recommended values are between 1 and 3. The default value is 1. """ options = _CommonOptions(**kwargs) try: samples = kwargs['samples'] assert(samples > 1) except KeyError: samples = 100 try: norm = float(kwargs['speedup']) assert(norm >= 1) except KeyError: norm = 1 simulation = _brain.Simulation(simulation) circuit = simulation.open_circuit() positions = circuit.positions( _rtneuron.util.targets_to_gids(targets, simulation)) top = positions.max(0) bottom = positions.min(0) center = (top + bottom) * 0.5 start = _compute_eye_position(positions, options) end = center end[2] = bottom[2] - (top[2] - bottom[2]) / 5.0 path = _rtneuron.CameraPath() for i in range(samples): i = 1 / (samples - 1.0) * i time = duration * i a = (1 - (1 - i) ** norm) ** (1 / norm) position = start * (1 - a) + end * a path.addKeyFrame(time, path.KeyFrame(position, ([1, 0, 0], 0), 1)) return path
def _ortho_frustum(positions, **kwargs): options = _CommonOptions(**kwargs) from rtneuron import CameraPath maxX, maxY = positions.max(0) minX, minY = positions.min(0) height = maxY - minY width = maxX - minX width /= 1 - options.air_pixels[0] height /= 1 - options.air_pixels[1] halfWidth = max(width, height * options.aspect_ratio) * 0.5 halfHeight = max(height, width / options.aspect_ratio) * 0.5 return [-halfWidth, halfWidth, -halfHeight, halfHeight]
def front_to_top_rotation(simulation, targets, duration=10, **kwargs): """Return a camera path of a rotation from front to top view of a set of circuit targets. This function will load the simulation config file given and all the neurons associated with the target specification. The front and top camera positions are computed based on the soma positions. The path duration is in seconds. The targets parameter can be: - A cell GID (as integer) - An iterable of GIDs - A target labels (as a string) - A list of any of the above The optional keyword arguments are: - timing: A [0..1]->[0..1] function used to map sample timestamps from a uniform distribution to any user given distribution. - samples: Number of keyframes to generate """ options = _CommonOptions(**kwargs) simulation = _brain.Simulation(simulation) circuit = simulation.open_circuit() gids = _rtneuron.util.targets_to_gids(targets, simulation) positions = options.fit_point_generator(gids, circuit) center = (positions.max(0) + positions.min(0)) * 0.5 # Computing the front position ensuring that after the rotation the circuit # will be correctly frames in the top view. front_eye = _compute_eye_position(positions, options) positions = positions[:,[0, 2, 1]] top_eye = _compute_eye_position(positions, options) top_eye[1], top_eye[2] = top_eye[2], top_eye[1] eye = front_eye if abs(eye[2] - center[2]) < abs(top_eye[1] - center[1]): eye[2] += (top_eye[1] - center[1]) - (eye[2] - center[2]) return rotation(center, [1, 0, 0], eye, -_math.pi/2, up="tangent", duration=duration, **kwargs)
def rotate_around(simulation, targets, duration=10, **kwargs): """Return a camera path of a front view rotation around a circuit target. This function will load the simulation config file given and all the neurons associated with the target specification. The start position is computed based on the soma positions. The path duration is in seconds. The target parameter can be: - A cell GID (as integer) - An iterable of GIDs - A target labels (as a string) - A list of any of the above """ options = _CommonOptions(**kwargs) simulation = _brain.Simulation(simulation) circuit = simulation.open_circuit() gids = _rtneuron.util.targets_to_gids(targets, simulation) positions = options.fit_point_generator(gids, circuit) center = (positions.max(0) + positions.min(0)) * 0.5 eye = _compute_eye_position(positions, options) return rotation(center, [0, 1, 0], eye, 2 * _math.pi, duration=duration)